Spree_auth_devise:如何添加create.js.erb文件?

时间:2017-01-08 15:04:10

标签: ruby-on-rails ajax ruby-on-rails-4 spree spree-auth-devise

我有模式表格登录:

= form_for(Spree::User.new, :url => spree.create_new_session_path, :as => :spree_user, html:{id: 'log_in_user', :'data-type' => 'json'}, remote: true) do |f|
  = f.email_field :email, :class => 'form-control', :tabindex => 1, :placeholder => Spree.t(:email)
  = f.password_field :password, :class => 'form-control', :tabindex => 2, :placeholder => Spree.t(:password)
  = f.submit 'Submit', :tabindex => 3, :class => 'btn btn-lg btn-success btn-blue'

和一些js进入我的welcome.js

$("form#log_in_user, form#register_user").bind("ajax:success", function(event, xhr, settings) {
    $(this).parents('.modal').modal('hide');
  })

它工作正常,但我想重新加载部分'登录栏'

我尝试创建user_sessions / create.js.erb

alert('123');
$(".user-area").load("<%= j render partial: 'shared/login_bar' %>");

但它不起作用。 所以我无法理解spree_auth_devise视图的工作原理,我在何处以及如何覆盖它们并添加我自己的js.erb文件。有什么帮助吗?

顺便说一下,user_sessions_controller.rb部分格式为.js:

def create
  if spree_user_signed_in?
      respond_to do |format|
        format.html {
          flash[:success] = Spree.t(:logged_in_succesfully)
          redirect_back_or_default(after_sign_in_path_for(spree_current_user))
        }
        format.js {
          render :json => {:user => spree_current_user,
                           :ship_address => spree_current_user.ship_address,
                           :bill_address => spree_current_user.bill_address}.to_json
        }
      end

1 个答案:

答案 0 :(得分:0)

app/views/spree/user_sessions/create.js.erb添加文件。

添加代码,

$(".user-area").html('<%= j render partial: "spree/shared/login_bar" %>');