Rails: render doesn't work, still get `Template is missing`

后端 未结 5 764
一个人的身影
一个人的身影 2021-02-02 08:59

I am currently learning Rails Guides. I went through the steps but still encountered a mistake.

My Ruby version is ruby 2.1.1p76 and the Rails version is

5条回答
  •  悲&欢浪女
    2021-02-02 09:54

    In the render method, plain option was added in Rails 4.1 and you are using Rails 4.0.4. So, rails ignored this option and started looking for a template named articles/create as you are in ArticlesController#create action. Obviously, the template doesn't exist so you get the error Template is missing.

    Refer to the discussion on this topic on Github: Introduce render :plain and render :html, make render :body as an alias to render :text

    Now, for using the below mentioned syntax you would need to upgrade to Rails 4.1:

    render plain: params[:article].inspect
    

    With your current version of Rails 4.0.4, you can go for:

    render text: params[:article].inspect
    

提交回复
热议问题