Hi, I have a simple program that tries to do something really basic. First, I have a company Model : ------------------------------------- class Company < ActiveRecord::Base has_one :billingAddress, :foreign_key=>"id", :class_name=>"Address" end Then I have the address Model : -------------------------------------- class Address< ActiveRecord::Base belongs_to :company end I''ve created manually an entry in the DB for Address and Company and I''ve linked them (Company table has a "billingAddress_id" row) In my views "company/_form"(scaffold generated), I want to display the address form. So I added (following Rails Guides) the following line to my view : <%= render :partial => "addresses/edit", :locals => { :shippingAddress => @address} %> It keeps saying : "undefined method `model_name'' for NilClass:Class " tried this : <%= render :partial => "addresses/edit", :locals => { @company.shippingAddress => @address} %> with the same result I''ve tried with : <%= render :partial => "addresses/form", :object => @billingAddress%> and I got the same result (this is normal I think since I don''t have a billingAddress object but a Company object. Finally, I''ve tried : <%= :partial => "addresses/form", :object => @company.shippingAddress %> and the error I got was : syntax error, unexpected tASSOC, expecting '') When I load the Company with rails console, it loads perfectly. However I cannot manage to call the aggregated object view since the name of the variable is not the same name as the class name... at least, that what I think it is :-) Can someone help me to figure this out ? I thought that this will be a simple task but it figures that it is not... Thank you very much for your time ! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 May 2010 13:49, Greg Raymond <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > I have a simple program that tries to do something really basic. > First, I have a company Model : > ------------------------------------- > class Company < ActiveRecord::Base > has_one :billingAddress, :foreign_key=>"id", :class_name=>"Address" > end > > Then I have the address Model : > -------------------------------------- > class Address< ActiveRecord::Base > belongs_to :company > end > > I''ve created manually an entry in the DB for Address and Company and > I''ve linked them (Company table has a "billingAddress_id" row) > > In my views "company/_form"(scaffold generated), I want to display the > address form. So I added (following Rails Guides) the following line to > my view : > > <%= render :partial => "addresses/edit", :locals => { :shippingAddress > => @address} %> > It keeps saying : "undefined method `model_name'' for NilClass:Class " > tried this :In the partial have you got something.model_name? If so then ''something'' is nil. In the traceback when you get the error message you should be able to see the line that is failing. Colin> <%= render :partial => "addresses/edit", :locals => { > @company.shippingAddress => @address} %> > with the same result > > I''ve tried with : > <%= render :partial => "addresses/form", :object => @billingAddress%> > and I got the same result (this is normal I think since I don''t have a > billingAddress object but a Company object. > > Finally, I''ve tried : > <%= :partial => "addresses/form", :object => @company.shippingAddress %> > and the error I got was : > syntax error, unexpected tASSOC, expecting '') > > When I load the Company with rails console, it loads perfectly. However > I cannot manage to call the aggregated object view since the name of the > variable is not the same name as the class name... at least, that what I > think it is :-) > > Can someone help me to figure this out ? I thought that this will be a > simple task but it figures that it is not... > > Thank you very much for your time ! > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote:> On 10 May 2010 13:49, Greg Raymond <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> class Address< ActiveRecord::Base >> <%= render :partial => "addresses/edit", :locals => { :shippingAddress >> => @address} %> >> It keeps saying : "undefined method `model_name'' for NilClass:Class " >> tried this : > > In the partial have you got something.model_name? If so then > ''something'' is nil. > > In the traceback when you get the error message you should be able to > see the line that is failing. > > ColinThanks Colin for the fast answer : In the partial I have the "standard" scaffolded code for my Address class So it''s a "form_for @address" just like Rails 3 is generates.... so I don''t understand why I can go to /addresses/1 and see the form but I cant view the same info via a partial. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 May 2010 14:04, Greg Raymond <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote: >> On 10 May 2010 13:49, Greg Raymond <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> class Address< ActiveRecord::Base >>> <%= render :partial => "addresses/edit", :locals => { :shippingAddress >>> => @address} %> >>> It keeps saying : "undefined method `model_name'' for NilClass:Class " >>> tried this : >> >> In the partial have you got something.model_name? If so then >> ''something'' is nil. >> >> In the traceback when you get the error message you should be able to >> see the line that is failing. >> >> Colin > Thanks Colin for the fast answer : > > In the partial I have the "standard" scaffolded code for my Address > class > > So it''s a "form_for @address" just like Rails 3 is generates....You did not say you are using Rails 3 (unless I missed it). I have no experience of Rails 3, which is still under development. You did not answer the question as to whether you are accessing something.model_name, nor whether the trace shows the failing line. You do not specify your knowledge level, if you are just starting I would not recommend rails 3. You will never know whether a problem is down to your experience or a problem with rails itself. Colin> > so I don''t understand why I can go to /addresses/1 and see the form but > I cant view the same info via a partial. > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 10, 2:49 pm, Greg Raymond <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > I have a simple program that tries to do something really basic. > First, I have a company Model : > ------------------------------------- > class Company < ActiveRecord::Base > has_one :billingAddress, :foreign_key=>"id", :class_name=>"Address" > endI think your problem is in :foreign_key=>"id" part. This means that foreign key to address is named ''id'' which is actually id column for Company model. Remove this part if your foreign key column is ''address_id'' or use real column name, i.e. ''billing_address_id'' otherwise Regards, Bosko -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> You did not say you are using Rails 3 (unless I missed it). I have no > experience of Rails 3, which is still under development. You did not > answer the question as to whether you are accessing > something.model_name, nor whether the trace shows the failing line. > > You do not specify your knowledge level, if you are just starting I > would not recommend rails 3. You will never know whether a problem is > down to your experience or a problem with rails itself. > > ColinHi Colin, Yes I''m using Rails 3. My knowledge level is ... well, begginer since I''m not able to make this thing works :-) My years of experience are with PHP and .Net. I''m trying Rails because it looks interesting and promising (once I''ll get a solid grip on basic things like this!) Here is my partial view for the Address class. 1<%= form_for(@address) do |f| %> 2 <div class="field"> 3 <%= f.label :city %><br /> 4 <%= f.text_field :city %> 5 </div> 6 7<% end %> The failling line is #3. I''m able to load the partial if I put in it a string and no code (like "<h1> TEST </h1>"). I''m not sure that I understand what you meant by "something.model_name" ... As for Rails 3, they said on guides.rails.info : "But if you’re starting development on a new application and you don’t mind getting wind in your hair, please do jump on board!" I''m starting a new app and I''m eager to learn so that''s what I''ve done.... is it a choice that bad ? Thank you for you replies ! Greg -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 May 2010 14:31, Greg Raymond <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:>> You did not say you are using Rails 3 (unless I missed it). I have no >> experience of Rails 3, which is still under development. You did not >> answer the question as to whether you are accessing >> something.model_name, nor whether the trace shows the failing line. >> >> You do not specify your knowledge level, if you are just starting I >> would not recommend rails 3. You will never know whether a problem is >> down to your experience or a problem with rails itself. >> >> Colin > > Hi Colin, > Yes I''m using Rails 3. My knowledge level is ... well, begginer since > I''m not able to make this thing works :-) My years of experience are > with PHP and .Net. I''m trying Rails because it looks interesting and > promising (once I''ll get a solid grip on basic things like this!) > > Here is my partial view for the Address class. > 1<%= form_for(@address) do |f| %> > 2 <div class="field"> > 3 <%= f.label :city %><br /> > 4 <%= f.text_field :city %> > 5 </div> > 6 > 7<% end %> > > The failling line is #3. I''m able to load the partial if I put in it a > string and no code (like "<h1> TEST </h1>"). I''m not sure that I > understand what you meant by "something.model_name"I think Bosko may well have the answer. I was assuming that one of your models had a file model_name but I see now that this is the rails model it is talking about. ... As for Rails 3,> they said on guides.rails.info : > > "But if you’re starting development on a new application and you don’t > mind getting wind in your hair, please do jump on board!" I''m starting > a new app and I''m eager to learn so that''s what I''ve done.... is it a > choice that bad ?I think this may have been intended for experienced users starting a new app rather than beginners. You will not find many tutorials and guides for rails 3 yet. I would consider going back to 2.3.x and starting with the guides at http://guides.rubyonrails.org/ Colin> > Thank you for you replies ! > Greg > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
@Bosko : I''ll try your suggestion tonight and keeps you posted. @Collin : Thanks for your time... I''ll check for rails 2.3.x and if I''m not able to make this work, I may roll back Thank you guys for your help ! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Possibly Parallel Threads
- undefined method `model_name' for NilClass:Class
- Please Help with single table inheritance relationships
- gmaps4rails: undefined method `model_name' for NilClass:Class
- undefined method `model_name' for NilClass:Class in a form_for
- Table relationships with single table inheritance