hello. first things first - I am new to ruby on rails (ruby, too), so I''m figuring this is just a basic newbie error. I''m creating a basic photography website. And I have two tables with a relationship: photos: - id (set up as PK) - title - shutter - aperture - date - the_order ...etc photo_comments: - id (set up as a PK) - photos_id (set up as a FK) - author - date - comment ...etc In my photo.rb model file i have this: class Photo < ActiveRecord::Base has_many :photo_comment # other code where I use ''find'' to get the photo info end This is all I have in my photo_comment.rb model file: class Photo_comment < ActiveRecord::Base belongs_to :Photo end>From here I''ll admit I''m a little lost as to how to procede. Right nowI''m just wanting to view the comments (i''ll worry about adding comments next... but one step at a time). In my photo_controller.rb file I get the desired photo like this: @photos = Photo.get_photo(params[:photo]) On the view side for this, I have this line to display the photo: <img src="/photos/<%= @photos.the_order %>.jpg" /> To get the comments, I''ve been trying to do something like this: <% for a_comment in @photos.photo_comment %> <p><%= a_comment.comment %></p> <% end %> However, when I run this code, I get this error: "uninitialized constant PhotoComment" Any suggestions on how to fix this, or am I approaching this the wrong way and need to do it differently? Thanks in advance, I appreciate it. -tyler -- Posted via http://www.ruby-forum.com/.
dblack@wobblini.net
2006-Mar-20 02:56 UTC
[Rails] has_many brings back ''uninitialized constant''
Hi -- On Mon, 20 Mar 2006, tyler wrote:> This is all I have in my photo_comment.rb model file: > class Photo_comment < ActiveRecord::Base > belongs_to :PhotoJust scanning quickly: change that to: class PhotoComment < ActiveRecord::Base belongs_to :photo and see if that helps :-) David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black
unknown wrote:> Hi -- > > On Mon, 20 Mar 2006, tyler wrote: > >> This is all I have in my photo_comment.rb model file: >> class Photo_comment < ActiveRecord::Base >> belongs_to :Photo > > Just scanning quickly: change that to: > > class PhotoComment < ActiveRecord::Base > belongs_to :photo > > and see if that helps :-) > > > Davidthanks for the reply. I changed it, but I still get the same error. -- Posted via http://www.ruby-forum.com/.
dblack@wobblini.net
2006-Mar-20 04:54 UTC
[Rails] has_many brings back ''uninitialized constant''
Hi -- On Mon, 20 Mar 2006, tyler wrote:> class Photo < ActiveRecord::Base > has_many :photo_commentMake that plural (:photo_comments). Another scattershot comment... sorry I''m being so fragmentary... but maybe that will straighten it out. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black
unknown wrote:> Hi -- > > On Mon, 20 Mar 2006, tyler wrote: > >> class Photo < ActiveRecord::Base >> has_many :photo_comment > > Make that plural (:photo_comments). Another scattershot comment... > sorry I''m being so fragmentary... but maybe that will straighten it > out. > > > David >I gave it a try, and I then go this error: "undefined method `photo_comment''" -- Posted via http://www.ruby-forum.com/.
dblack@wobblini.net
2006-Mar-20 14:23 UTC
[Rails] Re: has_many brings back ''uninitialized constant''
Hi -- On Mon, 20 Mar 2006, tyler wrote:> unknown wrote: >> Hi -- >> >> On Mon, 20 Mar 2006, tyler wrote: >> >>> class Photo < ActiveRecord::Base >>> has_many :photo_comment >> >> Make that plural (:photo_comments). Another scattershot comment... >> sorry I''m being so fragmentary... but maybe that will straighten it >> out. >> >> >> David >> > > I gave it a try, and I then go this error: > "undefined method `photo_comment''"The method will be "photo_comments". David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black
tyler
2006-Mar-20 23:56 UTC
[Rails] Re: Re: has_many brings back ''uninitialized constant''
unknown wrote:> > The method will be "photo_comments". >Thanks again for the response, but I still get this error: "uninitialized constant PhotoComment" -- Posted via http://www.ruby-forum.com/.
dblack@wobblini.net
2006-Mar-21 00:08 UTC
[Rails] Re: Re: has_many brings back ''uninitialized constant''
Hi -- On Tue, 21 Mar 2006, tyler wrote:> unknown wrote: >> >> The method will be "photo_comments". >> > > Thanks again for the response, but I still get this error: > > "uninitialized constant PhotoComment"I fear I''m out of ideas, based on what you''ve posted. Where (i.e., in what file) does the error seem to happen? David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black
tyler
2006-Mar-21 00:51 UTC
[Rails] Re: Re: Re: has_many brings back ''uninitialized constant''
David wrote:> > I fear I''m out of ideas, based on what you''ve posted. Where (i.e., in > what file) does the error seem to happen? > >It happens in my photo view. I''ve zipped up my app folder, thinking it would probably be easier for you to take a quick look at that rather than me trying to describe each file in a post. I will do a quick explanation of what I zipped though: I have two models-> photo.rb and photo_comment.rb, along with controllers to each of these. I have a view for the photo called ''get_info.rhtml'' This is the file that is throwing the error. I have it displaying the info for the photo correctly. It''s when I try to get comments on the photo that the error occurs. I''m referencing these two tables: photos: - id (set up as PK) - title - shutter - aperture - date - the_order ...etc photo_comments: - id (set up as a PK) - photos_id (set up as a FK) - author - date - comment ...etc Thank you so much for helping me with this, I really appreciate it. -- Posted via http://www.ruby-forum.com/.
tyler
2006-Mar-21 01:39 UTC
[Rails] Re: Re: Re: has_many brings back ''uninitialized constant''
would always help if i included the url, ehh? http://defocused.com/app.zip -- Posted via http://www.ruby-forum.com/.
dblack@wobblini.net
2006-Mar-21 02:16 UTC
[Rails] Re: Re: Re: has_many brings back ''uninitialized constant''
Hi -- On Tue, 21 Mar 2006, tyler wrote:> would always help if i included the url, ehh? > > http://defocused.com/app.zipIn my first response I said:> On Mon, 20 Mar 2006, tyler wrote: > > > This is all I have in my photo_comment.rb model file: > > class Photo_comment < ActiveRecord::Base > > belongs_to :Photo > > Just scanning quickly: change that to: > > class PhotoComment < ActiveRecord::Base > belongs_to :photo > > and see if that helps :-)and I *still* say that :-) You''ve still got Photo_comment. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black
tyler
2006-Mar-21 02:30 UTC
[Rails] Re: Re: Re: Re: has_many brings back ''uninitialized constant
David wrote:> > and I *still* say that :-) You''ve still got Photo_comment. > > > David > > -- > David A. Black (dblack@wobblini.net) > Ruby Power and Light, LLC (http://www.rubypowerandlight.com) > > "Ruby for Rails" chapters now available > from Manning Early Access Program! http://www.manning.com/books/blacki''m just shaking my head and feeling like a fool. I swear I did that... but must of done something else... as it''s working fine now. thank you so much, hope I didn''t waste too much of your time with this :-) -- Posted via http://www.ruby-forum.com/.