(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 via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Mon, Sep 17, 2012 at 9:31 AM, Bogdan M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> controller: > > def random > @task = Task.find(rand(Task.first.id..Task.last.id)) > # REMOVE - UNNECESSARY 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.@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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
well you are not using rest routes. it should look like : yourapp/tasks/4 rails would understand 4 as the param . On 17 set, 15:05, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mon, Sep 17, 2012 at 9:31 AM, Bogdan M. <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > controller: > > > def random > > @task = Task.find(rand(Task.first.id..Task.last.id)) > > # REMOVE - UNNECESSARY 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. > > @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.schroe...-Re5JQEeQqe80Tx58lXaADg@public.gmane.org://about.me/hassanschroeder > twitter: @hassan-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.