这是报错信息
RuntimeError in TopicsController#index
Circular dependency detected while autoloading constant Homeland::ApplicationController
module Homeland
class ApplicationController < ::ApplicationController
helper Homeland::ActionView::WillPaginate
helper Homeland::ApplicationHelper
helper_method :current_user, :owner?, :admin?
源码这里好像是没有写,不知道是不是漏掉了
TopicsController
module Homeland
class TopicsController < Homeland::ApplicationController
before_action :authenticate_user!, only: [:new, :edit, :create, :update, :destroy, :reply]
before_action only: [:edit, :update, :destroy] do
authorize_resource! topic
end
def index
@topics = Topic.latest.includes(:user).page(params[:page])
set_seo_meta(t("homeland.nav.latest"))
end
def node
@node = Node.find(params[:id])
@topics = @node.topics.latest.includes(:user).page(params[:page])
render action: "index"
end
%w(recent features).each do |action|
define_method(action) do
@topics = Topic.send(action).includes(:user, :node).page(params[:page])
set_seo_meta(t("homeland.nav.#{action}"))
render action: "index"
end
end
def show
@topic = Topic.find(params[:id])
@replies = replies
set_seo_meta(@topic.title)
end
def new
@topic = Topic.new
@node = Node.find_by(id: params[:node_id])
set_seo_meta(t("homeland.nav.new"))
end
def reply
@topic = Topic.find(params[:id])
@reply = @topic.replies.build(reply_params)
@reply.user_id = current_user.id
if @reply.save
flash[:notice] = t('homeland.reply_created')
else
flash[:alert] = @reply.errors.full_messages.join("<br />")
end
redirect_to topic_path(params[:id],:anchor => "reply")
end
# GET /topics/1/edit
def edit
@node = @topic.node
end
# POST /topics
# POST /topics.xml
def create
@topic = Topic.new(topic_params)
@topic.user_id = current_user.id
if @topic.save
redirect_to(topic_path(@topic.id), notice: t('homeland.topic_created'))
else
render action: "new"
end
end
# PUT /topics/1
# PUT /topics/1.xml
def update
@topic = Topic.find(params[:id])
if @topic.update_attributes(topic_params)
redirect_to(topic_path(@topic.id), notice: t('homeland.topic_updated'))
else
render action: "edit"
end
end
# DELETE /topics/1
# DELETE /topics/1.xml
def destroy
topic.destroy
redirect_to(topics_path, notice: t('homeland.topic_deleted'))
end
private
def topic
@topic ||= Topic.find(params[:id])
end
def replies
@topic.replies.includes(:user).page(params[:page])
end
def topic_params
params.require(:topic).permit(:node_id, :title, :body)
end
def reply_params
params.require(:reply).permit(:body, :reply_to_id)
end
end
end
application_controller
module Homeland
class ApplicationController < ::ApplicationController
helper Homeland::ActionView::WillPaginate
helper Homeland::ApplicationHelper
helper_method :current_user, :owner?, :admin?
alias_method :origin_current_user, Homeland.config.current_user_method.to_sym
alias_method :origin_authenticate_user!, Homeland.config.authenticate_user_method.to_sym
def current_user
origin_current_user
end
def authenticate_user!
origin_authenticate_user!
end
def authorize_resource!(obj)
if !owner?(obj)
redirect_to homeland.root_path, alert: t('homeland.access_denied')
end
end
def authorize_admin!
if !admin?
redirect_to homeland.root_path, alert: t('homeland.access_denied')
end
end
def set_seo_meta(title = '', meta_keywords = '', meta_description = '')
@page_title = "#{title}" if title.length > 0
@meta_keywords = meta_keywords
@meta_description = meta_description
end
def owner?(obj)
return false if obj.blank?
return false if current_user.blank?
return true if current_user.send(Homeland.config.user_admin_method) == true
obj.user_id == current_user.id
end
def admin?
return false if current_user.blank?
current_user.send(Homeland.config.user_admin_method) == true
end
end
end