Hi, I''m having some trouble with my realtions (I think). I''m creating a guestbook with comments in ajax (the structure resembles the structure of a blog). So I''ve got a "flogs table" which keeps the "user_id" and the "id" of the flogs. This table. Then I''ve got a "guestbooks table" containing "id" of the guestbooks, "flog_id", "title", "body", "created_at" and "updated_at". This one does NOT get created, resulting in (for example) "nil.title". (guestbook.title) Then I''ve got a "notes table" containing "id" of the notes, "user_id", "guestbook_id", "body" and "created_at". The realtions may be wrong here (at least that is what I suspect although I can''t see why they wouldn''t). user.rb has_many :notes, :order => "created_at DESC", :dependent => :destroy has_one :flog flog.rb belongs_to :user has_many :guestbooks, :order => "created_at DESC" guestbook.rb belongs_to :flog has_many :notes, :order => "created_at", :dependent => :destroy note.rb belongs_to :user belongs_to :guestbook -- 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 -~----------~----~----~----~------~----~------~--~---
furthermore, even if I manually add content to the table "guestbooks" i still get the same error... -- 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 26 May 2008, at 11:20, Dag Stensson wrote:> > Hi, > > I''m having some trouble with my realtions (I think). I''m creating a > guestbook with comments in ajax (the structure resembles the structure > of a blog). So I''ve got a "flogs table" which keeps the "user_id" and > the "id" of the flogs. This table. Then I''ve got a "guestbooks table" > containing "id" of the guestbooks, "flog_id", "title", "body", > "created_at" and "updated_at". This one does NOT get created, > resulting > in (for example) "nil.title". (guestbook.title) > > Then I''ve got a "notes table" containing "id" of the notes, "user_id", > "guestbook_id", "body" and "created_at". > > The realtions may be wrong here (at least that is what I suspect > although I can''t see why they wouldn''t). >You''ve shown us the relations (which appear at least vaguely sane (although I''m not entirely sure of the point of the flogs tables)) but not any of the code that is producing the error. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 26 May 2008, at 11:20, Dag Stensson wrote: > >> in (for example) "nil.title". (guestbook.title) >> >> Then I''ve got a "notes table" containing "id" of the notes, "user_id", >> "guestbook_id", "body" and "created_at". >> >> The realtions may be wrong here (at least that is what I suspect >> although I can''t see why they wouldn''t). >> > You''ve shown us the relations (which appear at least vaguely sane > (although I''m not entirely sure of the point of the flogs tables)) but > not any of the code that is producing the error. > > FredOkay, well, thanks Fred for checking it. Scratched the flog-table and placed the user_id in the guestbook table instead. If my relations are right, the fault may be in my Ajax code (and I''m very newbee to Ajax) so maybe this is what''s wrong. The main problem being "undefined local variable or method `guestbook'' for #<#<Class:0xaada638>:0xaada610>" when it gets the partial _post: "app/views/guestbook/_post.rhtml" ####################### index (presentation) ####################### <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <%= render :partial => ''header''%> <body> <%= render :partial => ''topmenu''%> <h1> <%= h @spec.full_name.or_else("Your Name") %>''s Presentation</h1> <h2>Presentation URL: <%= link_to presentation_for(@user), presentation_for(@user) %> </h2> <%= render :partial => ''content''%> <%= render :partial => "friendship/friends"%> <%= render :partial => "blog"%> <%= @guestbook_title %> <%= render :partial => "guestbook/post", :collection => @guestbooks %> </body> </html> ##################### _post ##################### <div class="guestbook"> <div id="notes_for_guestbook_<%= guestbook.id %>"> <%= render :partial => "notes/note", :collection => guestbook.notes %> </div> <% if logged_in? %> <div id="add_note_link_for_guestbook_<%= guestbook.id %>"> <%= link_to_remote "Add a comment", :url => new_note_path(guestbook), :method => :get %> </div> <div id="new_note_form_for_guestbook_<%= guestbook.id %>"> </div> <% end %> </div> ###################### _note ###################### <div id="note_<%= note.id %>" class="note"> <hr noshade /> <% if logged_in? and note.authorized?(User.find(session[:user])) %> <span class="edit_link" style="float: right"> <%= link_to_remote "(delete)", :url => note_url(note.guestbook, note), :method => :delete, :confirm => ''Are you sure?'' %> </span> <% end %> <%= link_to note.user.name, presentation_for(note.user) %> commented <%= time_ago_in_words note.created_at %> ago: <p> <%= sanitize note.body %> </p> </div> -- 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 -~----------~----~----~----~------~----~------~--~---
when you render a partial as collection like this:> <%= render :partial => "guestbook/post", :collection => @guestbooks %>you can''t access guestbook this way:> <div id="notes_for_guestbook_<%= guestbook.id %>">values handed to a partial as collection are known within the partial with the partials name <div id="notes_for_guestbook_<%= post.id %>"> should work. -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller wrote:> when you render a partial as collection like this: > >> <%= render :partial => "guestbook/post", :collection => @guestbooks %> > > you can''t access guestbook this way: >> <div id="notes_for_guestbook_<%= guestbook.id %>"> > > values handed to a partial as collection are known within the partial > with the partials name > > <div id="notes_for_guestbook_<%= post.id %>"> > > should work.Okay, thanks for explaining that, made a few more changes inside my partial after that, but now it renders a completely different error instead: "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id" I''m getting somewhat confused, is should get the id now (which exists in my guestbook table). Why does it get a nil? and what does 4 mean? -- 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 -~----------~----~----~----~------~----~------~--~---
> I''m getting somewhat confused, is should get the id now (which exists in > my guestbook table). Why does it get a nil? and what does 4 mean?get this error at the same place in code? (should not, since the partial is rendered as a collection...) the 4 is easy: it''s just the default id of the nil object. type nil.id in irb and you get this as result (together with the deprecated warning) pls post the error message, so we can see in which line it happens. -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller wrote:> > get this error at the same place in code? (should not, since the partial > is rendered as a collection...) >Same place in code> the 4 is easy: it''s just the default id of the nil object. type nil.id > in irb and you get this as result (together with the deprecated warning)okay, finally an explaination ;D> > pls post the error message, so we can see in which line it happens.RuntimeError in Presentation#show Showing app/views/guestbook/_post.rhtml where line #3 raised: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id Extracted source (around line #3): 1: <div class="guestbook"> 2: 3: <div id="notes_for_guestbook_<%= post.id %>"> 4: <%= render :partial => "notes/note", :collection => post.notes %> 5: </div> 6: -- 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 27 May 2008, at 10:53, Dag Stensson wrote:> > Thorsten Mueller wrote: >> >> pls post the error message, so we can see in which line it happens. > > RuntimeError in Presentation#show > > Showing app/views/guestbook/_post.rhtml where line #3 raised: > > Called id for nil, which would mistakenly be 4 -- if you really wanted > the id of nil, use object_id > > Extracted source (around line #3): > > 1: <div class="guestbook"> > 2: > 3: <div id="notes_for_guestbook_<%= post.id %>"> > 4: <%= render :partial => "notes/note", :collection => > post.notes %> > 5: </div> > 6:Sounds like the array you''ve passed to render has a nil in it. How are you populating it? Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 27 May 2008, at 10:53, Dag Stensson wrote: > >> the id of nil, use object_id >> >> Extracted source (around line #3): >> >> 1: <div class="guestbook"> >> 2: >> 3: <div id="notes_for_guestbook_<%= post.id %>"> >> 4: <%= render :partial => "notes/note", :collection => >> post.notes %> >> 5: </div> >> 6: > > Sounds like the array you''ve passed to render has a nil in it. How are > you populating it? > > Fredpresentation_controller, show method (looks the same in the index method): @guestbook = @user.guestbook ||= Guestbook.new -- 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 -~----------~----~----~----~------~----~------~--~---
> @guestbook = @user.guestbook ||= Guestbook.newin this case you get a single ActiveRecord object instead of the list of search results you would get with for example @guestbook = Guestbook.find(:all,...) to make this run you must use <%= render :partial => "guestbook/post", :object => @guestbook %> (and you mix the plural/singular form of @guestbook, make sure to use this consistent) -- 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 27 May 2008, at 11:18, Thorsten Mueller wrote:> > >> @guestbook = @user.guestbook ||= Guestbook.new > > in this case you get a single ActiveRecord object instead of the > list of > search results you would get with for example @guestbook > Guestbook.find(:all,...) > > to make this run you must use > > <%= render :partial => "guestbook/post", :object => @guestbook %> >Or is render :partial => "guestbook/post", :collection => @guestbook.posts what is intended ? Fred> (and you mix the plural/singular form of @guestbook, make sure to use > this consistent) > -- > 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 -~----------~----~----~----~------~----~------~--~---