質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

Q&A

0回答

1299閲覧

rails4でログインシステムを作りたいが、access deniedになる

tixure55

総合スコア400

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

0グッド

1クリップ

投稿2015/08/09 08:50

cancanとdeviceを使ってログイン認証画面を作ろうとしています。

http://blog.hrendoh.com/how-to-use-rails-admin/#.VccPkHXtmkoにあるように、ability.rbを下記のように書いたのですが、やはりdeniedになってしまいます。

#ablity.rb

ruby

1if user && user.admin? 2 can :access, :rails_admin # grant access to rails_admin 3 can :manage, :all # allow superadmins to do anything 4 end 5# Define abilities for the passed in user here. For example: 6# 7# user ||= User.new # guest user (not logged in) 8# if user.admin? 9# can :manage, :all 10# else 11# can :read, :all 12# end 13# 14# The first argument to `can` is the action you are giving the user 15# permission to do. 16# If you pass :manage it will apply to every action. Other common actions 17# here are :read, :create, :update and :destroy. 18# 19# The second argument is the resource the user can perform the action on. 20# If you pass :all it will apply to every resource. Otherwise pass a Ruby 21# class of the resource. 22# 23# The third argument is an optional hash of conditions to further filter the 24# objects. 25# For example, here the user can only update published articles. 26# 27# can :update, Article, :published => true 28# 29# See the wiki for details: 30# https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities 31user ||= User.new # guest user (not logged in) 32 if user.has_role?('admin') 33 can :manage, :all 34 end 35 end 36 end 37

http://ace-crc.hatenablog.com/entry/2015/05/10/145806に書いてあるconfig/initializers/rails_admin.rbのところを触らなければ、管理画面を表示させることはできております。

登録したメールアドレスとパスワードを入力して認証させる方法を教えてください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

rifuch

2015/08/09 23:18

cancanを導入する前の時点で、ログイン操作は正常にできますか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問