Parser error when using jQuery-UJS for remote link_to in Rails 3 app: how can I debug this?

后端 未结 7 1952
刺人心
刺人心 2021-02-14 12:55

I\'m trying to replace the content of a div after clicking on a link using Rails 3, remote_link :remote => true and jQuery.

So far, I\'ve been able to ge

7条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-14 13:37

    Another way to solve this is to add .js to the form's action (if you're using a Rails link generator you can add :format => :json). Then make sure you are responding to json in your controller.

    Here's an example of a sign in form configured that way:

        <%= form_for User.new, :url => session_path(:user, :format => :json), :html => {:id => "login-form", :class => "well"}, :remote => :true do |f| %>
          
          <%= f.text_field :email %>
          
          <%= f.password_field :password %>
          <%= f.hidden_field :remember_me %>
          <%= button_tag "Sign in", :class => "btn", :type => "submit" %><%= image_tag "ajax-loader.gif", :style => "display:none", :id => "login-spinner" %>
        <% end %>
    

    In the controller:

    def create
    respond_to do |format|
      format.html{ super }
      format.json do
       resource = warden.authenticate!(:scope => resource_name, :recall => :failure)
       return sign_in_and_redirect(resource_name, resource)
      end
    end
    end
    

提交回复
热议问题