0
我正在開發我的項目博客。我是一個新手開發人員使用Ruby on Rails ....BlogsController中的NoMethodError#show
我安裝了一個重擊寶石,然後安裝設計寶石auth ..我認爲這是一個身份驗證錯誤,但我不知道什麼是真的發生。我可以讓我的帖子顯示在我的索引視圖中,但是當我嘗試點擊顯示視圖的鏈接時,它顯示此錯誤...請幫助!!!
下面是我的控制器,路線和模型....
我不斷收到的錯誤是
NoMethodError在BlogsController#顯示
case filter when Symbol lambda { |target, _, &blk| target.send filter, &blk } when String l = eval "lambda { |value| #{filter} }" lambda { |target, value| target.instance_exec(value, &l) } ......
我的控制器
class BlogsController < ApplicationController
before_action :set_blog, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, only: [:new, :create, :edit, :update, :destroy]
def index
@blog = Blog.all
end
def new
@blog = Blog.new
end
def create
current_user.blogs.create(blog_params)
redirect_to blogs_path
end
def show
@blog = Blog.friendly.find(params[:id])
end
def edit
@blog = Blog.friendly.find(params[:id])
if @blog.user != current_user
return render text: 'Not Allowed', status: :forbidden
end
end
def update
@blog = Blog.friendly.find(params[:id])
if @blog.user != current_user
return render text: 'Not Allowed', status: :forbidden
end
@blog.update_attributes(blog_params)
redirect_to root_path
end
def destroy
@blog = Blog.friendly.find(params[:id])
if @blog.user != current_user
return render text: 'Not Allowed', status: :forbidden
end
@blog.destroy
redirect_to root_path
end
private
def blog_params
params.require(:blog).permit(:name, :description)
end
end
個
ROUTES
Rails.application.routes.draw do
devise_for :users
resources :blogs
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'portfolio#index'
end
模型
class Blog < ApplicationRecord
extend FriendlyId
friendly_id :name, use: :slugged
belongs_to :user
end