轨。重写间隙控制器

时间:2017-04-14 14:19:02

标签: ruby-on-rails ruby-on-rails-4 clearance

我尝试在间隙控制器中添加js。用户 - 控制器重写正常,但会话和密码控制器不起作用。

user_controller(work):

class UsersController < ApplicationController
  def new
  end

  def create
    @user = User.new(user_params)
    if @user.save
      sign_in @user
      redirect_to root_path
    else
      respond_to :js
    end
  end

  private

  def user_params
    params.require(:user).permit(
        :email,
        :password,
    )
  end
end

sessions_controller(不工作):

class SessionsController < ApplicationController    
  def new
      respond_to :js
  end

  def create
    respond_to :js

    @user = authenticate(params)

    sign_in(@user) do |status|
        if status.success?
            #redirect_back_or url_after_create
        else
            respond_to :js
        end
    end
  end
end

sessions / new.html.slim:

= form_for :session, html: {id: 'new_session', class: 'new_session'}, url: session_path, remote: true do |form|

  = form.label :email
  = form.text_field :email

  = form.label :password 
  = form.password_field :password 

  = form.submit "Log in"

节/ create.js.erb

$(".stuff").prepend("<div>It worked!</div>")

我的路线:

                 sign_in GET    /sign_in(.:format)                              clearance/sessions#new
                 session GET    /session(.:format)                              clearance/sessions#new
                sign_out DELETE /sign_out(.:format)                             clearance/sessions#destroy
                 sign_up GET    /sign_up(.:format)                              clearance/users#new
               passwords POST   /passwords(.:format)                            clearance/passwords#create
            new_password GET    /passwords/new(.:format)                        clearance/passwords#new
           session_index POST   /session(.:format)                              clearance/sessions#create
     user_password_index POST   /users/:user_id/password(.:format)              clearance/passwords#create
      edit_user_password GET    /users/:user_id/password/:id/edit(.:format)     clearance/passwords#edit
           user_password PATCH  /users/:user_id/password/:id(.:format)          clearance/passwords#update
                         PUT    /users/:user_id/password/:id(.:format)          clearance/passwords#update
                   users POST   /users(.:format)                                users#create

如何解决?

0 个答案:

没有答案