I really hope this is not a bad question (as in he''s abusing the list). However I could use a little direction (even though I''m reading books, tutorials) Right now I''m getting a undefined method `category'' for 4:Fixnum The specific lines from the rhtml file are: <td><%= link_to position.category_id.category, :action => "show", :id => position.id %></td> The "link_to position.category_id.category" is the real problem. So, In the Position model I have a belongs_to : category In the Category model I have a has_one : position I was under the grand illusion that from this point forward I could reference fields without additonal methods. hence, position.category_id.category. If I take out category and just leave position.category_id that displays fine. Any hints, tips or lambasting would be greatly appreciated. Oh did I mention I''m a beginner. (Counting 7 days today) Stuart TIA
On 6/14/06, Dark Ambient <sambient@gmail.com> wrote:> I really hope this is not a bad question (as in he''s abusing the > list). However I could use a little direction (even though I''m > reading books, tutorials) > > Right now I''m getting a > undefined method `category'' for 4:Fixnum > > The specific lines from the rhtml file are: > > <td><%= link_to position.category_id.category, :action => "show", :id > => position.id %></td> > > The "link_to position.category_id.category" is the real problem. > So, > > In the Position model I have a belongs_to : category > In the Category model I have a has_one : position > > I was under the grand illusion that from this point forward I > could reference fields without additonal methods. > hence, position.category_id.category. If I take out category and just > leave position.category_id that displays fine. > Any hints, tips or lambasting would be greatly appreciated. > > Oh did I mention I''m a beginner. (Counting 7 days today) > > Stuart TIA > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Try position.category instead of position.category_id.category (As an aside, you almost never see anything calling #category_id; it''s an intermediary for more common patterns like the one above) -- -Alder
Using position.category the page displayed a "#". Kind of weird. Stuart On 6/14/06, Alder Green <alder.green@gmail.com> wrote:> On 6/14/06, Dark Ambient <sambient@gmail.com> wrote: > > I really hope this is not a bad question (as in he''s abusing the > > list). However I could use a little direction (even though I''m > > reading books, tutorials) > > > > Right now I''m getting a > > undefined method `category'' for 4:Fixnum > > > > The specific lines from the rhtml file are: > > > > <td><%= link_to position.category_id.category, :action => "show", :id > > => position.id %></td> > > > > The "link_to position.category_id.category" is the real problem. > > So, > > > > In the Position model I have a belongs_to : category > > In the Category model I have a has_one : position > > > > I was under the grand illusion that from this point forward I > > could reference fields without additonal methods. > > hence, position.category_id.category. If I take out category and just > > leave position.category_id that displays fine. > > Any hints, tips or lambasting would be greatly appreciated. > > > > Oh did I mention I''m a beginner. (Counting 7 days today) > > > > Stuart TIA > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > Try position.category instead of position.category_id.category > > (As an aside, you almost never see anything calling #category_id; it''s > an intermediary for more common patterns like the one above) > > > -- > -Alder > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
You want something like: position.category.title or whatever the field/attribute is called that you want to display Dark Ambient wrote:> Using position.category the page displayed a "#". > > Kind of weird. > Stuart > > On 6/14/06, Alder Green <alder.green@gmail.com> wrote: >> On 6/14/06, Dark Ambient <sambient@gmail.com> wrote: >> > I really hope this is not a bad question (as in he''s abusing the >> > list). However I could use a little direction (even though I''m >> > reading books, tutorials) >> > >> > Right now I''m getting a >> > undefined method `category'' for 4:Fixnum >> > >> > The specific lines from the rhtml file are: >> > >> > <td><%= link_to position.category_id.category, :action => "show", :id >> > => position.id %></td> >> > >> > The "link_to position.category_id.category" is the real problem. >> > So, >> > >> > In the Position model I have a belongs_to : category >> > In the Category model I have a has_one : position >> > >> > I was under the grand illusion that from this point forward I >> > could reference fields without additonal methods. >> > hence, position.category_id.category. If I take out category and just >> > leave position.category_id that displays fine. >> > Any hints, tips or lambasting would be greatly appreciated. >> > >> > Oh did I mention I''m a beginner. (Counting 7 days today) >> > >> > Stuart TIA >> > _______________________________________________ >> > Rails mailing list >> > Rails@lists.rubyonrails.org >> > http://lists.rubyonrails.org/mailman/listinfo/rails >> > >> >> Try position.category instead of position.category_id.category >> >> (As an aside, you almost never see anything calling #category_id; it''s >> an intermediary for more common patterns like the one above) >> >> >> -- >> -Alder >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
position.category_id (comes from the positions table) category (comes from the categories table) so from the examples I''ve seen position.category_id.category should be the correct syntax. As a side note does it matter if I''ve not defined the foreign keys in the database ? Stuart On 6/14/06, Chris T <ctmailinglists@googlemail.com> wrote:> You want something like: > position.category.title or whatever the field/attribute is called that > you want to display > > > Dark Ambient wrote: > > Using position.category the page displayed a "#". > > > > Kind of weird. > > Stuart > > > > On 6/14/06, Alder Green <alder.green@gmail.com> wrote: > >> On 6/14/06, Dark Ambient <sambient@gmail.com> wrote: > >> > I really hope this is not a bad question (as in he''s abusing the > >> > list). However I could use a little direction (even though I''m > >> > reading books, tutorials) > >> > > >> > Right now I''m getting a > >> > undefined method `category'' for 4:Fixnum > >> > > >> > The specific lines from the rhtml file are: > >> > > >> > <td><%= link_to position.category_id.category, :action => "show", :id > >> > => position.id %></td> > >> > > >> > The "link_to position.category_id.category" is the real problem. > >> > So, > >> > > >> > In the Position model I have a belongs_to : category > >> > In the Category model I have a has_one : position > >> > > >> > I was under the grand illusion that from this point forward I > >> > could reference fields without additonal methods. > >> > hence, position.category_id.category. If I take out category and just > >> > leave position.category_id that displays fine. > >> > Any hints, tips or lambasting would be greatly appreciated. > >> > > >> > Oh did I mention I''m a beginner. (Counting 7 days today) > >> > > >> > Stuart TIA > >> > _______________________________________________ > >> > Rails mailing list > >> > Rails@lists.rubyonrails.org > >> > http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > >> > >> Try position.category instead of position.category_id.category > >> > >> (As an aside, you almost never see anything calling #category_id; it''s > >> an intermediary for more common patterns like the one above) > >> > >> > >> -- > >> -Alder > >> _______________________________________________ > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
The problem has nothing to do with link_to. What type is position.category_id? (I''ll give you a hint -- it begins with ''Fix'' and ends with ''num''.) -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Dark Ambient Sent: Wednesday, June 14, 2006 2:25 PM To: rails Subject: [Rails] Undefined method I really hope this is not a bad question (as in he''s abusing the list). However I could use a little direction (even though I''m reading books, tutorials) Right now I''m getting a undefined method `category'' for 4:Fixnum The specific lines from the rhtml file are: <td><%= link_to position.category_id.category, :action => "show", :id => position.id %></td> The "link_to position.category_id.category" is the real problem. So, In the Position model I have a belongs_to : category In the Category model I have a has_one : position I was under the grand illusion that from this point forward I could reference fields without additonal methods. hence, position.category_id.category. If I take out category and just leave position.category_id that displays fine. Any hints, tips or lambasting would be greatly appreciated. Oh did I mention I''m a beginner. (Counting 7 days today) Stuart TIA _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails Visit our website at http://www.ubs.com This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments.
Dark Ambient wrote:> Using position.category the page displayed a "#". > > Kind of weird.Not weird at all. View source in the browser and take a look at the raw html. If you don''t understand what you see, spend more time with Ruby, less with Rails. -- Posted via http://www.ruby-forum.com/.
On 6/14/06, Dark Ambient <sambient@gmail.com> wrote:> position.category_id (comes from the positions table) > category (comes from the categories table) > > so from the examples I''ve seen position.category_id.category should be > the correct syntax.Which example gave you that idea? Again, the whole point of Rails associations is to have #category_id as an implicit intermidiary. Read: almost never called directly. It is used internally for getting position.category, which is what you *really* want. Tha''st the point of the whole thing: get you what you want, with minimum typing.> > As a side note does it matter if I''ve not defined the foreign keys in > the database ? > > Stuart > > On 6/14/06, Chris T <ctmailinglists@googlemail.com> wrote: > > You want something like: > > position.category.title or whatever the field/attribute is called that > > you want to display > > > > > > Dark Ambient wrote: > > > Using position.category the page displayed a "#". > > > > > > Kind of weird. > > > Stuart > > > > > > On 6/14/06, Alder Green <alder.green@gmail.com> wrote: > > >> On 6/14/06, Dark Ambient <sambient@gmail.com> wrote: > > >> > I really hope this is not a bad question (as in he''s abusing the > > >> > list). However I could use a little direction (even though I''m > > >> > reading books, tutorials) > > >> > > > >> > Right now I''m getting a > > >> > undefined method `category'' for 4:Fixnum > > >> > > > >> > The specific lines from the rhtml file are: > > >> > > > >> > <td><%= link_to position.category_id.category, :action => "show", :id > > >> > => position.id %></td> > > >> > > > >> > The "link_to position.category_id.category" is the real problem. > > >> > So, > > >> > > > >> > In the Position model I have a belongs_to : category > > >> > In the Category model I have a has_one : position > > >> > > > >> > I was under the grand illusion that from this point forward I > > >> > could reference fields without additonal methods. > > >> > hence, position.category_id.category. If I take out category and just > > >> > leave position.category_id that displays fine. > > >> > Any hints, tips or lambasting would be greatly appreciated. > > >> > > > >> > Oh did I mention I''m a beginner. (Counting 7 days today) > > >> > > > >> > Stuart TIA > > >> > _______________________________________________ > > >> > Rails mailing list > > >> > Rails@lists.rubyonrails.org > > >> > http://lists.rubyonrails.org/mailman/listinfo/rails > > >> > > > >> > > >> Try position.category instead of position.category_id.category > > >> > > >> (As an aside, you almost never see anything calling #category_id; it''s > > >> an intermediary for more common patterns like the one above) > > >> > > >> > > >> -- > > >> -Alder > > >> _______________________________________________ > > >> Rails mailing list > > >> Rails@lists.rubyonrails.org > > >> http://lists.rubyonrails.org/mailman/listinfo/rails > > >> > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- -Alder
James, Yes, I saw the fixnum in the error message but didn''t think that would matter (I know , I was crazy to think that) Stuart On 6/14/06, James.Frohnhofer@ubs.com <James.Frohnhofer@ubs.com> wrote:> The problem has nothing to do with link_to. > > What type is position.category_id? (I''ll give you a hint -- it begins > with ''Fix'' and ends with ''num''.) > > -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Dark Ambient > Sent: Wednesday, June 14, 2006 2:25 PM > To: rails > Subject: [Rails] Undefined method > > I really hope this is not a bad question (as in he''s abusing the list). > However I could use a little direction (even though I''m reading books, > tutorials) > > Right now I''m getting a > undefined method `category'' for 4:Fixnum > > The specific lines from the rhtml file are: > > <td><%= link_to position.category_id.category, :action => "show", :id => > position.id %></td> > > The "link_to position.category_id.category" is the real problem. > So, > > In the Position model I have a belongs_to : category In the Category > model I have a has_one : position > > I was under the grand illusion that from this point forward I could > reference fields without additonal methods. > hence, position.category_id.category. If I take out category and just > leave position.category_id that displays fine. > Any hints, tips or lambasting would be greatly appreciated. > > Oh did I mention I''m a beginner. (Counting 7 days today) > > Stuart TIA > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > Visit our website at http://www.ubs.com > > This message contains confidential information and is intended only > for the individual named. If you are not the named addressee you > should not disseminate, distribute or copy this e-mail. Please > notify the sender immediately by e-mail if you have received this > e-mail by mistake and delete this e-mail from your system. > > E-mail transmission cannot be guaranteed to be secure or error-free > as information could be intercepted, corrupted, lost, destroyed, > arrive late or incomplete, or contain viruses. The sender therefore > does not accept liability for any errors or omissions in the contents > of this message which arise as a result of e-mail transmission. If > verification is required please request a hard-copy version. This > message is provided for informational purposes and should not be > construed as a solicitation or offer to buy or sell any securities or > related financial instruments. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 6/14/06, Dark Ambient <sambient@gmail.com> wrote:> position.category_id (comes from the positions table) > category (comes from the categories table)Yes, but you''re not dealing with fields in Ruby / Rails. Rails wraps all of this into objects. You''re dealing with objects in your view.> so from the examples I''ve seen position.category_id.category should be > the correct syntax.position.category.category would be my guess. Remember position.category is an object; your "belongs_to" and "has_many" tags indicate to the elves living in Rails that they should churn out a couple of classes wrapping some tables. Basically "position.category" gives you a CategoryModel model instance that contains the data for the appropriate category.> As a side note does it matter if I''ve not defined the foreign keys in > the database ?Nope. Rails creates objects, doesn''t care about the database beyond the "_id" column existing. I highly recommend reading the second half of Agile Web Development with Rails before straying too far from the core Depot example. Almost all of your questions willl be answered, the new release (as of yesterday, I think) even has a wonderful chapter on Migrations. ;) -Curtis
Curtis, Thanks for your help. Yes, I downloaded the AWSWR update last night. I am reading through the framework section and have done the depot tut. Admitedly I am trying to break away from depot (though still looking back). Anyway, something I''ll need to have sink in better is why postion.category.category worked! You wrote the explanation , very much appreciated. Stuart On 6/14/06, Curtis <cuspendlove@gmail.com> wrote:> On 6/14/06, Dark Ambient <sambient@gmail.com> wrote: > > position.category_id (comes from the positions table) > > category (comes from the categories table) > > Yes, but you''re not dealing with fields in Ruby / Rails. Rails wraps > all of this into objects. You''re dealing with objects in your view. > > > so from the examples I''ve seen position.category_id.category should be > > the correct syntax. > > position.category.category would be my guess. Remember > position.category is an object; your "belongs_to" and "has_many" tags > indicate to the elves living in Rails that they should churn out a > couple of classes wrapping some tables. Basically "position.category" > gives you a CategoryModel model instance that contains the data for > the appropriate category. > > > As a side note does it matter if I''ve not defined the foreign keys in > > the database ? > > Nope. Rails creates objects, doesn''t care about the database beyond > the "_id" column existing. > > I highly recommend reading the second half of Agile Web Development > with Rails before straying too far from the core Depot example. > Almost all of your questions willl be answered, the new release (as of > yesterday, I think) even has a wonderful chapter on Migrations. ;) > > > -Curtis > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 6/14/06, Dark Ambient <sambient@gmail.com> wrote:> Anyway, something I''ll need to have sink in better is why > postion.category.category worked! > You wrote the explanation , very much appreciated.I recommend as soon as possible reading the two ActiveRecord chapters, and everything will be made clear. :) It has in depth coverage of "belongs_to" and "has_many". ;) -Curtis
Reading part 2 now , read part 1 the other day. Probably a good idea to read over (and over ?) and hold closely for reference. My one problem with AWDWR and in particular the sections on ActiveRecord is that there is no explanation about where to put certain code he writes to try things out. As an example, on acts_as_list, he creates the tables, that is clear, add''s the methods and that is clear but then gives a method to exame the contents of the tables. Problem is where does that method go ? Lastly there is some code for manipulating the data, and that is fine provided it can be tested through the cosole. Stuart On 6/14/06, Curtis <cuspendlove@gmail.com> wrote:> On 6/14/06, Dark Ambient <sambient@gmail.com> wrote: > > Anyway, something I''ll need to have sink in better is why > > postion.category.category worked! > > You wrote the explanation , very much appreciated. > > I recommend as soon as possible reading the two ActiveRecord chapters, > and everything will be made clear. :) It has in depth coverage of > "belongs_to" and "has_many". ;) > > > -Curtis > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 6/14/06, Dark Ambient <sambient@gmail.com> wrote:> My one problem with AWDWR and in particular the sections on > ActiveRecord is that there is no explanation about where to put > certain code he writes to try things out.I typically use IRB or the rails console. Sometimes it''s enough to just study it until you understand why the output is what appears in the book. :) -Curtis