Hi,
I’m testing ajax in a restful resource.
In a non-restful controller, ajax worked fine.
But in a restful controller, ajax didn’t work as I expected.
I did the following.
- script/generate scaffold user name:string
- rake db:migrate
- In users_controller.rb, I added one line to the create method’s
response_to block.
format.js { render :layout => false }
- In index.html.erb, I added an ajax form.
<% remote_form_for :user, User.new, :url => users_path do |f| %>
<%= f.text_field :name %>
<%= submit_tag “Create” %>
<% end %>
- I created create.js.rjs and wrote a simple rjs code.
page.alert(“Test”)
When I clicked “Create” button, format.html was executed instead of
format.js.
So I changed the :url part.
:url => formatted_users_path(:js)
Now format.js is called but it displays the JavaScript code on a new
page.
It’s supposed to be evaluated, right?
What did I do wrong?
Thanks.
Sam