Hi Guys, I''m having a similar problem to someone earlier on the board, but the solutions posted aren''t working for me, so I figured I wouldn''t hijack the thread and started a new one: I have an application that allows users to post updates, when they go to the homepage I want the users details and a list of their updates to show, however I''m having trouble with the find parameters. Currently the model states that: user has_many: updates update belongs_to:user I think this is correct (and the right pluralisation)? the controller for the index page looks like this: def index @user = User.find(params[:id]) @updates = Update.find(params[:id]).updates end as explained in a previous thread (http://www.ruby-forum.com/topic/150785) I''ve also tried the different permutations of @updates = Update.find(:all, :conditions =>["user_id = ?",> params[:user_id]])-- 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 -~----------~----~----~----~------~----~------~--~---
Hi Guys, I''m having a similar problem to someone earlier on the board, but the solutions posted aren''t working for me, so I figured I wouldn''t hijack the thread and started a new one: I have an application that allows users to post updates, when they go to the homepage I want the users details and a list of their updates to show, however I''m having trouble with the find parameters. Currently the model states that: user has_many: updates update belongs_to:user I think this is correct (and the right pluralisation)? the controller for the index page looks like this: def index @user = User.find(params[:id]) @updates = Update.find(params[:id]).updates end as explained in a previous thread (http://www.ruby-forum.com/topic/150785) I''ve also tried the different permutations of @updates = Update.find(:all, :conditions =>["user_id = ?",> params[:user_id]])When visiting the page I get this messageL undefined method `updates'' for #<Update:0xb7582750> Have I missed something rediculously obvious? this seems like it should be a fairly trivial thing to get working but I''m pretty new to the whole rails experience... cheers, lee -- 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 -~----------~----~----~----~------~----~------~--~---
On 24 Apr 2008, at 21:07, Lee Farrar wrote:> > Hi Guys, > > I''m having a similar problem to someone earlier on the board, but the > solutions posted aren''t working for me, so I figured I wouldn''t hijack > the thread and started a new one: > > I have an application that allows users to post updates, when they > go to > the homepage I want the users details and a list of their updates to > show, however I''m having trouble with the find parameters. > > Currently the model states that: > > user has_many: updates > update belongs_to:user > > I think this is correct (and the right pluralisation)? > > the controller for the index page looks like this: > > def index > @user = User.find(params[:id]) > @updates = Update.find(params[:id]).updates >I think you just wanted to write @user.updates assuming that params[:id] is the id of a user. Fred> end > > as explained in a previous thread > (http://www.ruby-forum.com/topic/150785) > I''ve also tried the different permutations of > @updates = Update.find(:all, :conditions =>["user_id = ?", >> params[:user_id]]) > > When visiting the page I get this messageL > > undefined method `updates'' for #<Update:0xb7582750> > > Have I missed something rediculously obvious? this seems like it > should > be a fairly trivial thing to get working but I''m pretty new to the > whole > rails experience... > > cheers, > lee > -- > 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the quick reply Fred! the params [:id] is a users id yes, do you mean to change the controller to this: def index @user = User.find(params[:id]) @updates = @user.updates end this gave me an error of: You have a nil object when you didn''t expect it! The error occurred while evaluating nil.date with the lines: Extracted source (around line #19): 16: <h2>Updates</h2><br/> 17: <% for column in Update.content_columns %> 18: <p> 19: <b><%= column.human_name %>:</b> <%=h @update.send(column.name) %> 20: </p> 21: <% end %> 22: (which is where it begins outputting update information) could this point at an error somewhere else in my code (if its important, the app is mostly standard scaffold code) Frederick Cheung wrote:> On 24 Apr 2008, at 21:07, Lee Farrar wrote: > >> show, however I''m having trouble with the find parameters. >> def index >> @user = User.find(params[:id]) >> @updates = Update.find(params[:id]).updates >> > I think you just wanted to write @user.updates assuming that > params[:id] is the id of a user. > > Fred-- 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 -~----------~----~----~----~------~----~------~--~---
btw, I just realised I was calling it @updates in the controller and @update in the view, I fixed this and got a shiny new error: undefined method `date'' for Update:Class Extracted source (around line #19): 16: <h2>Updates</h2><br/> 17: <% for column in Update.content_columns %> 18: <p> 19: <b><%= column.human_name %>:</b> <%=h @updates.send(column.name) %> 20: </p> 21: <% end %> 22: date is a field name in the updates table. cheers, Lee -- 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 -~----------~----~----~----~------~----~------~--~---
at the risk of this becoming a monologue.. I''ve fixed the problem 19: <b><%= column.human_name %>:</b> <%=h @updates.send(column.name) needed to be 19: <b><%= column.human_name %>:</b> <%=h update.send(column.name) cheers for the help explaining how to reference the tables Fred! -- 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 -~----------~----~----~----~------~----~------~--~---