title: Rails4: What is the correct way to use form_for for submitting a hidden field
body: <p>I am trying to pass a hidden field from a form whose value is derived from a text blob that user can edit on the webpage. (I use bootstrap-editable to let the user edit the blurb by clicking on it)</p>
  
  <p>Here is the actual workflow:</p>
  
  <ol>
  <li>User goes on 'Invitations page' where they are are provided with a form to enter friends email and shown a <strong>default text</strong> that will be used in the email</li>
  <li>If the user want they can click on the text and edit it. This will make a post call via javascript to update_email method in Invitation controller</li>
  <li>After the text is updated user is redirected <strong>back</strong> so now the user sees the same page with updated text. <strong>This works</strong> and user sees the updated text blurb instead of default [1-3] can happen any number of times</li>
  <li>When the user submits the form , I expect to get the final version of email that I can save in the db and also trigger an email invitation to the users friend</li>
  </ol>
  
  <p>Problem:
  I keep getting <strong>default text</strong> from form parameters. Any idea what I am doing wrong?</p>
  
  <p>Here is the form (Its haml instead of html)</p>
  
  <pre><code>    #new-form
        = form_for @invitation, :url=&gt; invitations_path(), :html =&gt; {:class =&gt; 'form-inline', :role =&gt; 'form'} do |f|
          .form-group
            = f.text_field :email, :type=&gt; 'email', :placeholder=&gt; 'Invite your friends via email', :class=&gt; 'form-control invitation-email'
            = f.hidden_field :mail_text, :value =&gt; @invitation_email
          = f.submit :class =&gt; 'btn btn-primary submit-email', :value =&gt; 'Send'
  </code></pre>
  
  <p>Here is the invitation controller:</p>
  
  <pre><code>class InvitationsController &lt; ApplicationController
    authorize_resource
    before_filter :load_invitations, only: [:new, :index]
    before_filter :new_invitation, only: [:new, :index]
    before_filter :default_email, only: [:index]
    #helper_method :default_email
  
    def create
      Invitation.create!(email: params[:invitation][:email], invited_by: current_user.id, state: 'sent', mail_text: params[:invitation][:mail_text], url: {referrer_name: current_user.name}.to_param)
      redirect_to :back
    end
  
    def update_email
      @invitation_email = params[:value]
      flash[:updated_invitation_email] = params[:value]
      redirect_to :back
    end
  
    private
  
    def invitation_params
      params.require(:invitation).permit!
    end
  
    def load_invitations
      @invitations ||= current_user.sent_invitations
    end
  
    def new_invitation
      @invitation  = Invitation.new
    end
  
    def default_email
      default_text = "default text"
      @invitation_email = flash[:updated_invitation_email].blank?  ?  default_text : flash[:updated_invitation_email]
    end
  end
  </code></pre>