Yeah, I state corrected, but my point remains..

On Sunday, June 14, 2015 at 4:38:17 PM UTC-4, Colin Law wrote:
>
> On 14 June 2015 at 18:55, Elizabeth McGurty <[email protected] 
> <javascript:>> wrote: 
> > Just wondering why you don't validate the presence/absence of 
> gender_name on 
> > creation of a new record... 
>
> I think it is not gender_name that is missing, but the gender object 
> itself. 
>
> Colin 
>
> > 
> > 
> > 
> > On Sunday, June 14, 2015 at 3:27:56 AM UTC-4, Ruby-Forum.com User wrote: 
> >> 
> >> please help solve the problem. 
> >> 
> >> There is a table users: 
> >> id :integer, autoincrement 
> >> name :string 
> >> gender_id :integer 
> >> 
> >> There is a table genders: 
> >> id :integer, autoincrement 
> >> gender_name :string 
> >> 
> >> model User: 
> >> class User < ActiveRecord::Base 
> >>   belongs_to  :gender 
> >> end 
> >> 
> >> model Gender: 
> >> class Gender < ActiveRecord::Base 
> >>   has_many  :users 
> >> end 
> >> 
> >> I need the gendername. I try to do so: 
> >> <% @users.each do |user| %> 
> >>     <div class="col-xs-6"><%= user.name %></div> 
> >>     <div class="col-xs-2"><%= user.gender_id %></div> 
> >> <% end %> 
> >> 
> >> the result is output number, but I need to gendername 
> >> 
> >> 
> >> 
> >> 
> >> p.s. 
> >> so I tried: 
> >> <div class="col-xs-2"><%= user.gender.gender_name %></div> 
> >> 
> >> in this case receives the following error message: 
> >> undefined method `gender_name' for nil:NilClass 
> >> 
> >> -- 
> >> 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 unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to [email protected] <javascript:>. 
> > To post to this group, send email to [email protected] 
> <javascript:>. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/rubyonrails-talk/63e2564a-c5a0-4043-94da-3b110971fb8e%40googlegroups.com.
>  
>
> > 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/b250e620-0c3d-428f-8e95-6b377677bcaf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to