Кажется простым, в моей модели у меня есть:
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 !@account.has_valid_user?(current_user)
set_current_account(@account)
@latest_contacts = Contact.latest_contacts(current_account)
end
end
То, что в настоящее время находится в route.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 отобразился в представлении для страницы учетной записи клиента.
ОБНОВЛЕНИЕ:
Вот код, который в конечном итоге работал в rout.rb,который я обнаружил после просмотра примеров в ответе ниже:
resources :customer_accounts, :path => '/:id' do
root :action => "show"
member do
get 'disabled'
post 'update_billing'
end
end