Forum: Ruby on Rails Cannot redirect to nil! - basic MVC operation

Posted by Bogdan M. (bogdan_m)
on 2012-09-17 18:31
(I'm having some hard time for days to manage to chose a random item
from teh database and to be able to pass it further.)

It is basic operation and i tried several ways all,  brought me to the
same problem,  params {"id" = "random"} <- the name of the controller
method

controller:

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 %>   # i want it to make it work, if i pass manually
lets #say `../random/1` lets say as an example it works it shows me the
memory #location of the object.

error log:

 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"}
Posted by Hassan Schroeder (Guest)
on 2012-09-17 20:06
(Received via mailing list)
On Mon, Sep 17, 2012 at 9:31 AM, Bogdan M. <lists@ruby-forum.com> wrote:

> memory #location of the object.
@task.inspect would be more useful, or actually displaying some
specific attributes of the object :-)

> error log:
>
>  ActionController::ActionControllerError in TasksController#show
> Cannot redirect to nil!

But here, you're not even using your "random" method, you're calling
"show" -- check your routes.

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Posted by rodrigo coutinho (Guest)
on 2012-09-18 23:16
(Received via mailing list)
well you are not using rest routes.
it should look like :
yourapp/tasks/4
rails would understand 4 as the param .
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.