Search code examples
javascriptruby-on-railsruby-on-rails-3jqueryajax-on-rails

undefine method submit_to_remote


<%= submit_to_remote(:category, :url => params[:id].blank? ? {:action => 'create'} : {:action => "update", :id => @category}) do %>
    <table>
        <tr>
            <th>Name</th>

        </tr>

        <tr>
            <td><%= text_field(:category, :name, :size => 20) %></td>
            <td><%= submit_tag(params[:id].blank? ? "New": "Edit") %></td>
        </tr>
    </table>
<% end %>

I want to create new record using Ajax. I got error undefined method submit_to_remote I declared prototype file in layout. waiting for ans.......


Solution

  • Firstly, it looks like your submit_to_remote is trying to define a form - so use form_for or form_tag.

    Secondly submit_to_remote no longer exists in Rails 3. You need the :remote => true option of form_tag, which will let UJS (Unobtrusive JavaScript) step in and make the AJAX happen.

    See some docs.