ruby - update action not working in rails 4 -
when updating form throwing error field unique.
in model
validates :url, presence: true, uniqueness: true, :if => lambda {self.role_id == 2}
in form
= f.text_field :url, :class => 'form-control'
in controller
def update respond_to |format| if @user.update(user_params) format.html { redirect_to stores_path, notice: 'store updated.' } else format.html { render :edit } end end end
even if not doing giving me error "this url has been taken". please in advance
i resolved way.
def update respond_to |format| if @user.update(user_params) format.html { redirect_to stores_path, notice: 'store updated.' } else incoming_url = user.where("id=? , url=?",@user.id,params[:user][:url]) if !incoming_url.blank? format.html { redirect_to stores_path, notice: 'store updated.' } end format.html { render :edit } end end end
Comments
Post a Comment