Rjs is either not ignored or not evaluated

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.

  1. script/generate scaffold user name:string
  2. rake db:migrate
  3. In users_controller.rb, I added one line to the create method’s
    response_to block.

format.js { render :layout => false }

  1. 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 %>

  1. 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs