I have this form which has a whole bunch of stuff for a user to fill out, not all of the fields have to be filled, but the one that are left blank I need to enter a dummie value for in the database because all that stuff gets entered later on into another form consisting of edit_in_place fields. The way I have it now is that a method gets called after a user profile is created and sets all the values to a dummie string if they are blank, the problems is that there are so many field in the table that the method is very long because of all the fields. Bacisally I''m saying if if @user.address.blank? @user.address = "Empty" Is there a way to do this which isn''t as long and maybe more programmatically correct? Thanks, -S -- 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 -~----------~----~----~----~------~----~------~--~---
i think validates_each should be, what you''re looking for: http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001324 something on that line: validates_each :email, :phone, :on => :create do |record, attr, value| if value.blank? ... end -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller wrote:> validates_each :email, :phone, :on => :create do |record, attr, value| > if value.blank? ... > endI think you are correct and that this is exactly what I want, but it doesn''t save the values when I create a new object. I have a model for user and am trying to save stuff on save. Here is what I got: validates_each :company, :on => :save do|record, attr, value| if value.blank? attr = "Click to Edit" end end I tried to say record.attr = "Click to Edit" but that didn''t seem to work. When I create a new user it seems to run through the whole process - the validates_each too, but it doesn''t save. Is there something that I''m missing? Thanks, -S -- 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 -~----------~----~----~----~------~----~------~--~---
Why does the value need to be in the database? Why not override the display of the column for empty? have it output what every you want. On Feb 8, 4:09 pm, Shandy Nantz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Thorsten Mueller wrote: > > validates_each :email, :phone, :on => :create do |record, attr, value| > > if value.blank? ... > > end > > I think you are correct and that this is exactly what I want, but it > doesn''t save the values when I create a new object. I have a model for > user and am trying to save stuff on save. Here is what I got: > > validates_each :company, :on => :save do|record, attr, value| > if value.blank? > attr = "Click to Edit" > end > end > > I tried to say record.attr = "Click to Edit" but that didn''t seem to > work. When I create a new user it seems to run through the whole process > - the validates_each too, but it doesn''t save. Is there something that > I''m missing? Thanks, > > -S > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
brewpoo wrote:> Why does the value need to be in the database? Why not override the > display of the column for empty? have it output what every you want. > > On Feb 8, 4:09 pm, Shandy Nantz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Because later on in another part of the form I display the values in in_place_edit fields and if the values are empty strings then I can''t edit the values by clicking on them because there is nothing to click on. -S -- 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 -~----------~----~----~----~------~----~------~--~---