Route Constraint for admin, Slug refactored to a concern

This commit is contained in:
Saurabh Bhatia 2014-04-03 11:17:07 +08:00
parent e5d3d10263
commit 3ca008e041
11 changed files with 51 additions and 13 deletions

View File

@ -14,8 +14,8 @@ gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# gem 'announcement', git: 'git@gitlab.tp.rulingcom.com:saurabh/announcement-test.git'
gem 'announcement', path: "/Volumes/MyData/github/orbit4.5/announcement"
gem 'announcement', git: 'git@gitlab.tp.rulingcom.com:saurabh/announcement-test.git'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

View File

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the admin/dashboards controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,4 @@
class Admin::DashboardsController < ApplicationController
def index
end
end

View File

@ -0,0 +1,2 @@
module Admin::DashboardsHelper
end

View File

@ -1,16 +1,17 @@
module Slug
extend ActiveSupport::Concern
def slug
if not respond_to? :title or title.empty?
id
else
I18n.locale
title.parameterize
end
included do
before_create :generate_uid
end
def to_param
slug
[self.title.gsub(/[ "'*@#$%^&()+=;:.,?>|\\<~_!]/,'-').gsub(/-{2,}/,'-'), self.uid].join("-")
end
private
def generate_uid
self.uid = rand(36**8).to_s(36)
end
end

View File

@ -0,0 +1,2 @@
<h1>Admin::Dashboards#index</h1>
<p>Find me in app/views/admin/dashboards/index.html.erb</p>

View File

@ -0,0 +1,6 @@
class KeywordConstraint
def matches?(request)
keywords = %w{admin member desktop}
keywords.all? { |k| !request.url.include?(k) }
end
end

View File

@ -1,5 +1,9 @@
OrbitStore::Application.routes.draw do
namespace :admin do
get 'dashboards/index'
end
get "/pages/edit_view" => "pages#edit_view"
get "/pages/preview" => "pages#preview"
@ -18,7 +22,7 @@ OrbitStore::Application.routes.draw do
# You can have the root of your site routed with "root"
root 'home#index'
scope "(:locale)", locale: /en|zh_tw/ do
get ':page(/:page)(/:page)(/:page)', to: 'pages#show'
get ':page(/:page)(/:page)(/:page)', to: 'pages#show', constraints: KeywordConstraint.new
resources :pages
end
# Example of regular route:

View File

@ -0,0 +1,9 @@
require 'test_helper'
class Admin::DashboardsControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
end
end

View File

@ -0,0 +1,4 @@
require 'test_helper'
class Admin::DashboardsHelperTest < ActionView::TestCase
end