0
<%= 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.......

imKalpesh
  • 91
  • 1
  • 10
  • You've asked 12 questions, but you haven't given any of the answers a single up-vote, or marked any answers as correct. People will be more likely to help you if you show a little appreciation for their efforts. – Chowlett Oct 25 '12 at 13:10

1 Answers1

2

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.

Chowlett
  • 45,935
  • 20
  • 116
  • 150
  • is any more other changes needed? – imKalpesh Oct 25 '12 at 13:11
  • Hard to say without a fair bit more code. But assuming this is a form for a `Category` model, and you have an `@category` in hand (either new or existing), then it looks like a all right start. – Chowlett Oct 25 '12 at 13:16