send data from view to controller in rails
<p>I want to send some data from view to controller in rails through ajax.</p>

<p>I have the following code in
app/view/static/home.html.erb</p>

<pre><code> &lt;script type="text/javascript"&gt;
        var dummy = "testtext";
        $('#finish').click(function() {
          $.ajax( {
            url: '/finish',
            type: 'POST',
            data: dummy,
            dataType: 'text'
          });
         });
      &lt;/script&gt;

      &lt;body&gt;
        &lt;%= button_to "Finish", {:action =&gt; 'finish', :controller =&gt; 'static'}, :method =&gt; :post, id =&gt; 'finish' %&gt;
      &lt;/body&gt;
</code></pre>

<p>in 
app/view/static/finish.html.erb</p>

<pre><code>&lt;p&gt;&lt;%= @data %&gt;&lt;/p&gt;
</code></pre>

<p>app/controller/static_controller.rb</p>

<pre><code>def finish
@data = params[:data]
end
</code></pre>

<p>in routes.rb</p>

<pre><code>post 'finish' =&gt; 'static#finish'
</code></pre>

<p>My understanding is that on button click the ajax script will be executed and rails action will store the data passed from view. This doesn't seem to work. I'm not sure if my understanding of the flow is right.</p>