前提・実現したいこと
railsでログイン機能を作成しております。
sorceryというgemを使っているのですが、上手く動かず苦戦しております。
どうか解決方法を教えていただければと思います。
発生している問題・エラーメッセージ
エラーが発生しておらず四苦八苦しております泣
UsersController
def new @user = User.new end def show @user = User.find(params[:id]) end def create @user = User.new(user_params) if @user.save redirect_to user_path(@user), notice: "Signed up!" else render :new, ntice: "Failed to signin" end end private def user_params params.require(:user).permit(:email, :password, :password_confirmation) end
###SessionsController
def new end def create user = login(params[:email], params[:password]) if user redirect_back_or_to user_path(user), notice: "Logged in!" else flash.now[:alert] = "Failed to login" render :new end end def destroy logout redirect_to root_path, notice: "Logged out!" end
###User.rb
authenticates_with_sorcery! validates :email, uniqueness: true validates :password, length: { minimum: 6 }, if: -> { new_record? || changes["password"] } validates :password, confirmation: true, if: -> { new_record? || changes["password"] } validates :password_confirmation, presence: true, if: -> { new_record? || changes["password"] }
###view
<h1 class="page-title">ログイン画面</h1> <fieldset> <h1 class="login-box-title">ログイン</h1> <% if logged_in? %> <%= current_user.email %> <% end %> <form> <%= form_tag sessions_path, :method => "post" do %> <div class="fieldbox"> <div class="iconemail"></div> <%= text_field_tag :email, params[:email], :placeholder => "Email", class: "field" %> </div> <div class="fieldbox"> <div class="iconpassword"></div> <%= password_field_tag :password, params[:password], :placeholder => "Password", class: "field" %> </div> <%= submit_tag "ログイン", :class => "login-submit" %> <% end %> <%= link_to "Signup", new_user_path %> </form> </fieldset>
###command
Started GET "/sessions/new?utf8=%E2%9C%93&authenticity_token=wT178RGZPFMiCRONYlOUupGYpvIphzdFN%2BWO6YMNDX0kYpkyXxdo1Zw9JZQgk3unr5sxfhnD%2BRjxcNIK5NlZiw%3D%3D&email=admin%40example.com&password=[FILTERED]&commit=%E3%83%AD%E3%82%B0%E3%82%A4%E3%83%B3" for 10.0.2.2 at 2018-01-30 03:39:32 +0000 Cannot render console from 10.0.2.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 Processing by SessionsController#new as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"wT178RGZPFMiCRONYlOUupGYpvIphzdFN+WO6YMNDX0kYpkyXxdo1Zw9JZQgk3unr5sxfhnD+RjxcNIK5NlZiw==", "email"=>"admin@example.com", "password"=>"[FILTERED]", "commit"=>"ログイン"} Rendering sessions/new.html.erb within layouts/application Rendered sessions/new.html.erb within layouts/application (1.3ms) Completed 200 OK in 160ms (Views: 124.6ms | ActiveRecord: 0.0ms)
試したこと
routingやらいろいろなサイトを拝見させていただきましたが、
全く一緒にしたところで動きが変わらない。。。
なぜでしょう泣
補足情報(FW/ツールのバージョンなど)
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
Rails 5.1.4
centos
MariaDB
あなたの回答
tips
プレビュー