title: Rails: how to send a string from controller to view?
body: <p>I'm new to rails and I want my controller to update label/html field in view with the variable @msg created from an action. right now I have,</p>
  
  <p>View form:</p>
  
  <pre><code>&lt;%= form_tag({controller: "home", action: "drawMoney"}) do %&gt;
  &lt;h1&gt; Draw Out &lt;/h1&gt;
      &lt;%= number_field_tag :draw, min: 1, max:1000 %&gt;
      &lt;%= date_field_tag :customDate %&gt;
  &lt;%= submit_tag "Save" %&gt;
  &lt;% end %&gt;
  
  &lt;p&gt;
    &lt;%= "#{@msg}" %&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>def drawMoney
  @drawAmount = params[:draw]
  @credit = Credit.getCredit('1')
  @updateAmount = updatePrincipal(@credit.principal, @drawAmount)
  @newLimit = updateLimit(@credit.currLimit, @drawAmount)
  
  @msg = "success!"
  
  if (@transaction = Transaction.create(userId: @credit.userId, date: params[:customDate], OPB: @credit.principal, amount: @drawAmount).valid?)
    @credit.update(principal: @updateAmount, currLimit: @newLimit)
    @transaction = Transaction.create(userId: @credit.userId, date: params[:customDate], OPB: @credit.principal, amount: @drawAmount)
  else
    @msg = "not valid"
  end
  
  redirect_to action: "index"
  end
  </code></pre>
  
  <p>I've read ruby docs and youtube tutorial, tried putting @msg in the view instead and @msg in html etc.. but this is not printing anything to the view, and couldn't really find answers from search. Any help would be appreciated!</p>
  
  <p>EDIT:</p>
  
  <p>I tried changing to &lt;%= @msg %> but it doesn't work..
  so the method is called when I click the submit button, and until then there is no @msg instance. Could that be a problem?</p>