I have an activerecord model Student. In show action of Student controller i retrieve the database data about a Student and display it in the view. Student object has fields like age, gender, dateofbirth, address, etc where a few fields are optional. Now in my view i display like this Name : <%= @student.name %> Age : <%= @student.age %> I don''t want the optional field labels to get displayed. So i used <% if @student.address.nil? %> -- 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 -~----------~----~----~----~------~----~------~--~---
Sorry for posting wrongly I have an activerecord model Student. In show action of Student controller i retrieve the database data about a Student and display it in the view. Student object has fields like age, gender, dateofbirth, address, etc where a few fields are optional. Now in my view i display like this Name : <%= @student.name %> Age : <%= @student.age %> I don''t want the optional field labels to get displayed. So i used <% if @student.address.nil? %> Address : <%= @student.address %> <% end %> Does this method affect the performance of rendering the view? Thank you -- 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 -~----------~----~----~----~------~----~------~--~---
Rock Roll wrote:> I have an activerecord model Student. In show action of Student > controller i retrieve the database data about a Student and display it > in the view. Student object has fields like age, gender, dateofbirth, > address, etc where a few fields are optional. Now in my view i display > like this > > > Name : <%= @student.name %> > Age : <%= @student.age %> > > I don''t want the optional field labels to get displayed. So i used > > <% if @student.address.nil? %> > Address : <%= @student.address %> > <% end %> > > Does this method affect the performance of rendering the view?Only very slightly. It''s not worth worrying about. By the way, you want to use an "unless" rather than an "if". You could speed it up slightly: <%= "Address : #{@student.address}" if @student.address %> -- Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.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 -~----------~----~----~----~------~----~------~--~---