Rails 5.0.0.1で開発しています。
以下の通り、before_actionを設定しており、indexアクションでは適用外にしたいのですが、コードを記載しても添付写真のエラーが出てしまいます。before_action :signin_required, except: [:index, :show]を消すと、動作に問題はありません。
解決方法をご教示頂けますと幸甚です。
ruby
1class User::ProductsController < User::Base 2 before_action :signin_required, except: [:index, :show] 3 4 def index 5 if params[:user_id] 6 @user = User.find(params[:user_id]) 7 @products = @user.products 8 else 9 @products = Product.all.order("id") 10 end 11 end 12 13 def search 14 @user = current_user 15 @products = Product.search(params[:q]) 16 render "index" 17 end 18 19 def show 20 @product = Product.find(params[:id]) 21 end 22 23 def new 24 @product = Product.new(posted_at: Time.current) 25 end 26 27 def edit 28 @product = current_user.products.find(params[:id]) 29 end 30 31 def create 32 @product = Product.new(product_params) 33 @product.user = current_user 34 if @product.save 35 redirect_to [current_user, :user_products] 36 else 37 render "edit" 38 end 39 end 40 41 def update 42 @product = current_user.products.find(params[:id]) 43 @product.assign_attributes(product_params) 44 if @product.save 45 redirect_to [current_user, :user_products] 46 else 47 render "edit" 48 end 49 end 50 51 def like 52 @product = Product.find(params[:id]) 53 current_user.voted_products << @product 54 redirect_to [current_user, :user_product], notice: "投票しました" 55 end 56 57 def unlike 58 current_user.voted_products.destroy(Product.find(params[:id])) 59 redirect_to :voted_user_products, notice: "削除しました。" 60 end 61 62 def voted 63 @products = current_user.voted_products.order("votes.created_at DESC") 64 end 65 66 private 67 def product_params 68 params.require(:product).permit(:price, :brand, :memo, :dispatch, :posted_at) 69 end 70end 71

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/05 08:10
退会済みユーザー
2016/11/05 09:52