2012-01-04 6 views
1

それは私が持っている私のモデルでは、簡単なようだ:ruby​​ 3.1のstringex gemによって生成されたslug URLにマップするルートを追加するにはどうすればよいですか?

class CustomerAccount < ActiveRecord::Base 

    acts_as_url :name 

    def to_param 
    url # or whatever you set :url_attribute to 
    end 

end 

そして、私のコントローラでは、私が持っている:

class CustomerAccountsController < ApplicationController 
    def show # dashboard for account, set as current account 
    @account = CustomerAccount.find_by_url params[:id] 
    no_permission_redirect if [email protected]_valid_user?(current_user) 
    set_current_account(@account) 

    @latest_contacts = Contact.latest_contacts(current_account) 
    end 
end 

何routes.rbを現在だことは次のとおりです。

resources :customer_accounts, :path => :customer_accounts.url do 
    member do 
     get 'disabled' 
     post 'update_billing' 
    end 
    end 

rake db:seedを介してデータを生成しようとすると、次のようなエラーが発生します。少なくとも、ルート内のエントリがそれを実行していると仮定します。

undefined method `url' for :customer_accounts:Symbol 

ルートを設定するにはどうすればよいですか?私が望むのはhttp://0.0.0.0/customeraccountnameで、顧客アカウントページのビューにマップします。

UPDATE:ここ

が、私は以下の答えの例を見た後に発見routes.rbをして働くことになったコードは、次のとおりです。

resources :customer_accounts, :path => '/:id' do 
    root :action => "show" 
    member do 
     get 'disabled' 
     post 'update_billing' 
    end 
    end 

答えて

2

あなたがそれを設定したい場合あなたは、この下にdisabledupdate_billingアクションをしたい場合は

get '/:id', :to => "customer_accounts#show" 

:あなたが表示さのようなので、これを行うと、ルートを持っている

get '/:id/disabled', :to => "customer_accounts#disabled" 
post '/:id/update_billing', :to => "customer_accounts#update_billing" 
また

(およびずっとすっきり):

scope '/:id' do 
    controller "customer_accounts" do 
    root :action => "show" 
    get 'disabled' 
    get 'update_billing' 
    end 
end 
+0

私はそれを望んだ道を働くことになった何が、私はあなたの例を見て後にハックアップデート、です。 –

関連する問題