Ruby on rails Ruby on Rails视图未拉入application.html.erb布局

Ruby on rails Ruby on Rails视图未拉入application.html.erb布局,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我的rails应用程序中的一组视图有一些问题。我创建了ran scaffold来创建POST模型、控制器和视图。它们自己工作得很好,但拒绝使用application.html.erb布局 这是邮政调度员: class PostsController < ApplicationController before_action :set_post, only: [:show, :edit, :update, :destroy] # GET /posts # GET /posts.

我的rails应用程序中的一组视图有一些问题。我创建了ran scaffold来创建POST模型、控制器和视图。它们自己工作得很好,但拒绝使用application.html.erb布局

这是邮政调度员:

class PostsController < ApplicationController
  before_action :set_post, only: [:show, :edit, :update, :destroy]

  # GET /posts
  # GET /posts.json
  def index
    @posts = Post.all
  end

  # GET /posts/1
  # GET /posts/1.json
  def show
  end

  # GET /posts/new
  def new
    @post = Post.new
  end

  # GET /posts/1/edit
  def edit
  end

  # POST /posts
  # POST /posts.json
  def create
    @post = Post.new(post_params)

    respond_to do |format|
      if @post.save
        format.html { redirect_to @post, notice: 'Post was successfully created.' }
        format.json { render action: 'show', status: :created, location: @post }
      else
        format.html { render action: 'new' }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /posts/1
  # PATCH/PUT /posts/1.json
  def update
    respond_to do |format|
      if @post.update(post_params)
        format.html { redirect_to @post, notice: 'Post was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /posts/1
  # DELETE /posts/1.json
  def destroy
    @post.destroy
    respond_to do |format|
      format.html { redirect_to posts_url }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_post
      @post = Post.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def post_params
      params.require(:post).permit(:title, :body, :datecreated, :datemodified, :published, :author)
    end
end
rails生成的其他文件夹也在那里,我刚刚展示了与问题相关的内容

ApplicationController确实继承自ActionController::Base,这是整个文件:

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
end
class ApplicationController
pages控制器看起来很相似,这些页面可以正确地拖动application.html.erb,而无需任何特殊工作

这是github上的回购协议。也许这会有更大帮助。

有几件事(应该是一个评论,但为了清楚起见,我会写在这里):

  • 检查您是否有
    app/views/layouts/application.html.erb
  • 检查您是否有
    app/controllers/application\u controller.rb
    继承自
    ActionController::Base
  • 当你提到使用
    时,你是什么意思?这是在哪里渲染的?如果它是从动作中呈现的,它将自动显示在应用程序布局上

    您能否为我们发布更多代码,特别是
    posts\u controller
    application\u controller
    routes
    application
    布局文件?

    有几件事(应该是一个注释,但为了清楚起见,我会在这里写):

  • 检查您是否有
    app/views/layouts/application.html.erb
  • 检查您是否有
    app/controllers/application\u controller.rb
    继承自
    ActionController::Base
  • 当你提到使用
    时,你是什么意思?这是在哪里渲染的?如果它是从动作中呈现的,它将自动显示在应用程序布局上


    你能为我们发布更多的代码吗,特别是
    posts\u controller
    application\u controller
    routes
    application
    布局文件?

    在我的例子中,只有一个控制器的视图没有使用
    layouts/application.html.erb
    进行渲染。结果表明,所讨论的控制器是从
    ActionController::Base
    继承的,而不是从
    ApplicationController
    继承的

    不正确:

       MyController < ActionController::Base
    
    MyController
    正确:

       MyController < ApplicationController
    
    MyController
    在我的例子中,只有一个控制器的视图没有使用
    layouts/application.html.erb
    进行渲染。结果表明,所讨论的控制器是从
    ActionController::Base
    继承的,而不是从
    ApplicationController
    继承的

    不正确:

       MyController < ActionController::Base
    
    MyController
    正确:

       MyController < ApplicationController
    
    MyController
    目录结构中的
    application.html.erb
    在哪里?它是发生在所有控制器上,还是只发生在一个控制器中的一个或一个操作(如果是,是哪个操作?)您的
    application.html.erb
    的文件结构是什么?它应该是
    app/views/layouts/application.html.erb
    您的应用程序
    ApplicationController
    应该继承自
    ActionController::Base
    。它应该是这样的:
    ApplicationController
    编辑了这篇文章,其中包含了评论中的更多信息,这个文件应该命名为
    application\u html.erb
    ?这是更新问题时的一个输入错误吗?Rails通常希望文件名为
    application.html.erb
    目录结构中的
    application.html.erb
    在哪里?它是发生在所有控制器上,还是只发生在一个控制器中的一个或一个操作(如果是,是哪个操作?)您的
    application.html.erb
    的文件结构是什么?它应该是
    app/views/layouts/application.html.erb
    您的应用程序
    ApplicationController
    应该继承自
    ActionController::Base
    。它应该是这样的:
    ApplicationController
    编辑了这篇文章,其中包含了评论中的更多信息,这个文件应该命名为
    application\u html.erb
    ?这是更新问题时的一个输入错误吗?Rails通常希望将文件命名为
    application.html.erb
       MyController < ApplicationController