我有這樣的代碼鏈接到一個新的角色:Rails的routes.rb中不工作根據需要與命名路由
<%= link_to "New Persona", genesis_path, class: "new-persona-button" %>
我的routes.rb文件:
Bazleyapp::Application.routes.draw do
resources :users, only: [:index, :create]
resources :personas, only: [:index, :create]
root 'static_pages#home'
get 'signup', to: 'users#new'
get '/:callsign', to: 'users#show', as: :user
get '/:callsign/settings', to: 'users#edit', as: :edit_user
patch '/:callsign', to: 'users#update', as: :update_user
delete '/:callsign/terminated', to: 'users#destroy', as: :destroy_user
get 'genesis', to: 'personas#new'
get '/:callsign', to: 'personas#show', as: :persona
get '/:callsign/settings', to: 'personas#edit', as: :edit_persona
patch '/:callsign', to: 'personas#update', as: :update_persona
delete '/:callsign/terminated', to: 'personas#destroy', as: :destroy_persona
end
點擊新角色按鈕產生此錯誤:
Started GET "/genesis" for ::1 at 2014-12-03 00:25:38 +0000
Processing by UsersController#show as HTML
Parameters: {"callsign"=>"genesis"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."callsign" = $1 LIMIT 1 [["callsign", "bazzer"]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."callsign" = $1 LIMIT 1 [["callsign", "genesis"]]
Completed 500 Internal Server Error in 21ms
NoMethodError (undefined method `activated' for nil:NilClass):
app/controllers/users_controller.rb:17:in `show'
這意味着當它應該擊中genesis_p時它正在觸及user_path(users#show) ATH。但我已經告訴它<%= link_to "New Persona", genesis_path, class: "new-persona-button" %>
打的起源路徑。我很困惑。錯誤在哪裏?
但是,爲什麼不使用'genesis_path'告訴它直來直去的角色/新的動作? – Bazley 2014-12-03 17:16:54