Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Quynh To Tuan8,192 Points
"render text:" shows error
The "render text:" in #show does not work. I get the error message: "Missing template pages/show". Why is it still looking for a template although we are using "render text"?
This is the code snippet:
render text: params[:id]
Jay McGavrenTreehouse Teacher
yvesramos I'll update the teacher's notes to mention
plain work in Rails 5.0, which is the recommended version for this course. It's important to use the recommended versions of libraries when following along with tutorials. This is just one example of the incompatibilities that can happen when the versions differ.
You can install Rails 5.0 with this command:
gem install rails --version 5.0.0
As I write, this installs Rails 5.0.4, which is okay because (unlike 5.1.2) its API is still fully compatible with 5.0.0.
rails new uses the newest version of Rails installed on your system by default. If you already have a more recent version of Rails (such as 5.1) installed on your system, and you don't want to uninstall it, you'll need to ensure that you're using 5.0.0 when generating a new app. Use this command:
rails _5.0.0_ new blog
Once you change into your app's directory, as long as you're running commands using
bin/rails (which is what we suggest in the course), it should use the version of Rails that the app was generated with.
Thanks, Zia Khan. It worked with plain:. For those having the same issue and wonder why we can not use text: it is because is deprecated. This link might help(https://apidock.com/rails/ActionController/Base/render). I am not sure, but I think they removed it in rails 4.2. Jay, you should test it and add it in the teacher notes.
Vladislav Trotsenko9,291 Points
With Rails 5.1.4 I have used:
@page = Page.find(params[:id])
render plain: @page.title
or you can use
render text: @page.title, but you should create app/views/pages/show.html.erb if you don't want to get 'Template is missing' error :)