What makes the data prepopulate a field if a Form Fails?
I made this fo开发者_如何学Crm almost entirely from scratch and AJAX which is why it's not working, I'm assuming.
But I instantiate my form in my controller as so..
def skip_to_end
@card_signup ||= CardSignup.new(params[:card_signup])
respond_to do |wants|
wants.html { redirect_to new_card_signup_path }
wants.json { render :json => { :html => (render_to_string :partial => '/card_signups/new_form') } }
end
end
The form looks like this :
- form_for @card_signup do |f|
= f.text_field :first_name, :style => "width: 166px;", :value => "first name", :rel => "first name"
%div{:class => 'error_message'}
....
And when I try and save it halfway complete, it goes to my create
action :
def create
@card_signup = current_user.build_card_signup(params[:card_signup])
if @card_signup.valid?
respond_to do |wants|
#wants.html { redirect_to disclaimer_card_signup_path, :locals => { :card_signup => @card_signup } }
wants.json { render :json => { :html => (render_to_string :partial => 'disclaimer') } }
end
else
respond_to do |wants|
#wants.html { redirect_to new_card_signup_path }
wants.json { render :json => {:errors => @card_signup.errors, :html => (render_to_string :partial => '/card_signups/new_form') } }
end
end
end
It then fails, and returns back to the original form, but with all the forms cleared.
How can I make it so that the fields are at the very least prepopulated with what they had in them previously?
精彩评论