Spree_auth_devise: how to add create.js.erb file?

318 views Asked by At

I have modal form to sign-in:

= 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'

and some js into my welcome.js

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

It works fine, but i want to reload partial 'login-bar'

I tried to create user_sessions/create.js.erb

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

But it doesn't work. So i can't undestand how spree_auth_devise views works, where and how i can override them and add my own js.erb files. Any help?

By the way, user_sessions_controller.rb part with format.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

There are 1 answers

5
Priyank Gupta On

Add a file at app/views/spree/user_sessions/create.js.erb.

Add code,

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