• 不行 还是报错

  • 好的

  • 这是目录

  • 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
    
    
  • 看了下 ,有些不明白有什么用处 只是记录生活

  • 我还是不太明白啊 你发的链接我看过了 那是讲的rails怎么加载的 我这个是根本不知道这是什么原因导致的这个问题发生的 是没加载到 还是有什么依赖?

  • 好的 谢谢

  • 刚刚才查到的 是顶层的命名空间;我想问问 我的这个报错是什么原因呢 不是很理解

  • 访问 127.0.0.1:3000 :

    Showing /home/deploy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/homeland-1.0.1/app/views/layouts/homeland/application.html.erb where line #5 raised:
    
    couldn't find file 'homeland' with type 'application/javascript'
    Checked in these paths: 
    
    //= require_tree .
    /*
     *= require homeland
     */