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
You no need template means you could use render nothing: true
Try like this:
class ArticlesController < ApplicationController
def new
end
def create
params[:article].inspect
render nothing: true
end
end
Please refer this link click here
You may want to read through the following documentation.
Rendering pure text is most useful when you're responding to Ajax or web service requests that are expecting something other than proper HTML.
Change Rails version in your Gemfile:
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.6'
Then run:
bundle install
Make sure that your Rails version now is > 4.1
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
If you want to see textual information of params[:article] on your page then you can use render text
try this
class ArticlesController < ApplicationController
def new
end
def create
render text: params[:article].inspect
end
end
You will get
{"title"=>"First article!", "text"=>"This is my first article."}
# i.e. your params(whatever params hash contains)