超簡単な質問があります。アプリ内のすべての製品を一覧表示するページがあります。そのページを管理者だけが閲覧できるようにしたいだけです。でも商品・新作はみんなにはっきりと見てもらいたい。
schema.rb
create_table "users", :force => true do |t|
t.string "email"
t.string "password_hash"
t.string "password_salt"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "name"
t.boolean "admin", :default => false
end
製品コントローラ
class ProductsController < ApplicationController
before_filter :require_login
before_filter :current_user, only: [:create, :destory]
before_filter :correct_user, only: :destory
def index
@products = Product.all
end
def new
@product = Product.new
end
def create
@product = current_user.products.new(params[:product])
if @product.valid?
@product.save
render "show", :notice => "Sale created!"
else
render "new", :notice => "Somehting went wrong!"
end
end