Part of my application should show a list of all users on the system who agreed to have their details revealed. So, I have an action like this: def view_users @users = User.find(:all,:conditions=>"reveal = 1",:order=>"login DESC") end In the associated view, @users is an object of nilclass and the app. breaks as it tries to iterate over the @users array. However, if I include this at the top of view_users.rhtml <% @users = User.find(:all,:conditions=>"reveal = 1",:order=>"login DESC") %> ...then everything works as expected.Why should this be? Thanks. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Part of my application should show a list of all users on the system who > agreed to have their details revealed. So, I have an action like this: > > def view_users > @users = User.find(:all,:conditions=>"reveal = 1",:order=>"login > DESC") > end > > In the associated view, @users is an object of nilclass and the app. > breaks as it tries to iterate over the @users array. However, if I > include this at the top of view_users.rhtml > > <% @users = User.find(:all,:conditions=>"reveal = 1",:order=>"login > DESC") %> > > ...then everything works as expected.Why should this be?My guess is that somewhere (perhaps an after_filter or a partial) you''re setting @users to nil. What happens if in your controller right after that find() call you do: render :text => @users.inspect, :layout => false return Do you get all your users then? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom wrote:> What happens if in your controller right after that find() call you do: > > render :text => @users.inspect, :layout => false > return > > Do you get all your users then?That works - many thanks. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Christoph Olszowka
2007-Mar-02 11:30 UTC
Problem with functional test & RESTful url-helpers
Hello there, I ran into a problem with my shiny new RESTful controller. One of it''s partial templates is using a custom member action''s url helper created by map.resources, e.g. "something_model_url(id)". This works perfectly when I try it in my webbrowser, but my functional test fails when it gets to "display" the mentioned partial, telling me: Exception: undefined method "something_model_url" for #<#<Class...> On line #22 of (...) Obviously the helper does not get defined. I already know that the routing is not being processed in functional tests due to performance reasons, but there must be a way to still access my partials?! So I guess I am searching for the magic "bring me some url-helpers" trigger in my functional tests. Any suggestions will be greatly appreciated! Greetings, Christoph --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Philip Hallstrom wrote: >> What happens if in your controller right after that find() call you do: >> >> render :text => @users.inspect, :layout => false >> return >> >> Do you get all your users then? > > That works - many thanks.Then somewhere after your find() call, but before your view you are trashing @users.... :/ --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Just to add a quick note about a ''gotcha'' that bit me in the early days... Philip Hallstrom wrote:> Then somewhere after your find() call, but before > your view you are trashing @users....If you''re doing a redirect_to, that''ll trash your instance variables. Best regarsd, Bill --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> If you''re doing a redirect_to, that''ll trash your instance variables.All fixed now, thanks. This has been useful at improving my understanding of how rails works. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Christoph Olszowka
2007-Mar-06 15:13 UTC
Re: RESTful URL-Helpers causing functional test failure
Hi Folks, I still can''t figure out what the problem could be. It seems it''s only the singular_url helpers that are missing, the plural_url helpers do not lead to test failure. Did really no one else run into something like this? Greetings, Christoph Christoph Olszowka schrieb:> Hello there, > > I ran into a problem with my shiny new RESTful controller. > One of it''s partial templates is using a custom member action''s > url helper created by map.resources, e.g. "something_model_url(id)". > This works perfectly when I try it in my webbrowser, but my functional > test fails when it gets to "display" the mentioned partial, telling > me: > Exception: undefined method "something_model_url" for #<#<Class...> > On line #22 of (...) > > Obviously the helper does not get defined. I already know that the > routing is not being processed in functional tests due to performance > reasons, but there must be a way to still access my partials?! So > I guess I am searching for the magic "bring me some url-helpers" trigger > in my functional tests. Any suggestions will be greatly appreciated! > > Greetings, > Christoph > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---