ruby on rails - Persist form value on new user registration (devise) -
i have new user registration form , persist values in form if validations fail. did not see way this.
right in controller have
def create .....code...... @user = user.new params[:user] redirect_to new_user_registration_url(@user) end however, not working. needs done accomplish persistent values after validation?
you don't want redirect on validation failures. should render new action (or whatever appropriate in situation). redirect not have access of instance variables calling context; it's new request. typical setup this:
def somecontroller < applicationcontroller def new @foo = foo.new end def create @foo = foo.new(params[:foo]) if @foo.save redirect_to foo_path(@foo) else render action: 'new' end end end the render action: here can little confusing. doesn't call action; instead renders default view action. in case, if foo fails save, render new form, instead of being populated new foo, populated foo failed save. you'll values in form again. typically when render form (or in layout), check , render errors might exist on model (@foo).
Comments
Post a Comment