(我有一些艱難的時間,幾天來管理從德數據庫中選擇一個隨機項 ,並能夠進一步通過。)無法重定向到零! - 基本MVC操作
這是基本的操作和我嘗試幾種方法所有,把我帶到了 同樣的問題,則params { 「ID」= 「隨機」} < - 控制器的名稱 方法
控制器:
def random # method works checked it in the console. Returns a valid obj.
@task = Task.find(rand(Task.first.id..Task.last.id))
render "random"
end
random.html.erb <%= @task %>
#我想讓它工作,如果我手動通過 讓#say ../random/1
可以說作爲一個例子它的作品它顯示了我的 對象的內存#位置。
錯誤日誌:
ActionController::ActionControllerError in TasksController#show
Cannot redirect to nil!
Rails.root: /home/bogdan/ex/bored
Application Trace | Framework Trace | Full Trace
actionpack (3.2.3) lib/action_controller/metal/redirecting.rb:60:in
`redirect_to'
actionpack (3.2.3) lib/action_controller/metal/flash.rb:25:in
`redirect_to'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:60:in
`block in redirect_to'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `block
in instrument'
activesupport (3.2.3)
lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in
`instrument'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:59:in
`redirect_to'
actionpack (3.2.3) lib/action_controller/metal/implicit_render.rb:4:in
`send_action'
actionpack (3.2.3) lib/abstract_controller/base.rb:167:in
`process_action'
.
.
.
(only the top of the stack)
Request
Parameters:
{"id"=>"random"}
編輯: 無聊:: Application.routes.draw做
roots.rb:
to => 'tasks#main'
resources :tasks
match ':controller(/:action(/:id))(.:format)'
你的路線將有所幫助。這可能是問題的根源。 –
你可以通過@test = Task.first來快速測試,從圖片中獲得更多的複雜性。如果這仍然是壞的,因爲它可能是,我敢打賭你的路線是RESTful而不是匹配 –
添加routes.rb –