Hello, I have the following in my def create controller: @photo = current_user.photos.create(params[:photo].merge(:project_id => params[:project_id]) In my app photo records are valid if they have a project_id or not.... But I need my create statement not to error and work for both cases. CASE A. If there is a param project_id, insert it CASE B. If not, insert the default NULL value when creating the record What''s the smartest Rails3 way to accomplish this? Thanks -- 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.
Robert Pankowecki (rupert)
2010-Oct-09 08:15 UTC
Re: Rails 3- Handling a conditional Create in a Controller
@photo = current_user.photos.create(params[:photo]) Keep :project_id in params[:photo]. Use hidden field on form that submits the data or regular select tag if you let the use choose the project. What makes you think that it won''t work ? There is no special case here. Robert Pankowecki -- 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.