ruby on rails - How to reject update attribute if param is blank or empty? -


i have form

view

<%= simple_form_for user.new |f| %>    <%= f.input :email %>    <%= text_field_tag "user[data[first_name]]" %>    <%= f.button :submit %> <% end %> 

controller#create

@user = user.find_or_initialize_by_email(params[:user][:email])  if @user.update_attributes(params[:user])   ... 

how reject update user hstore date attribute if params(in case first_name) empty or blank?

in opinion taking wrong strategy create action. do

@user = user.new(params[:user]) @user.save 

if want ensure email unique across users, use rails' validation so:

class user   #...   validates_uniqueness_of :email   #... end 

your approach modify existing user same email during create. sounds wrong.

for more details, have @ create of scaffolded controller.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -