Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
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:
def show render text: params[:id] end
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:
def show @page = Page.find(params[:id]) render plain: @page.title end
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 :)