Problem using render text in basic rails application

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem using render text in basic rails application

Robert Phillips
It works fine as far as this

C:\blah>rails new test1

C:\blah\test1>rails server

I edit application_controller.rb

I add a function called hello

def hello
   render plain: "aasdf"
end

I edit the routes.rb file

I add this line into the existing  procedure within routes.rb   root 'application#hello'

I access 127.0.0.1:3000/    and it shows  aasdf  

So that's all fine

But here's the problem

If I edit application_controller.rb and change that line from  render plain: "aasdf"   into  render text: "hello world!"   then it doesn't work. Though https://www.railstutorial.org/book/static_pages   suggests using  render text: "hello world!".   in the application controller hello procedure.
i.e.

def hello
   render text: "hello world!"
end


I get the error  "

Missing template application/hello with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :jbuilder]}. Searched in: * "C:/blah/test1/app/views""


And if I change it to one suggestion regarding that kind of error, that I saw online, the suggesetion is to add a parameter of content_type: 'text/plain'  i.e. 

def hello
   render text: "hello world!", content_type: 'text/plain'
end

Then I get the same error

Where am I going wrong here?

Thanks

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/eb8a4956-0925-4085-aefc-cb13eedecd0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problem using render text in basic rails application

Phil Edelbrock

render text: is deprecated.  Stick with render plain: .


Phil


On Jan 7, 2018, at 2:12 PM, Robert Phillips <[hidden email]> wrote:

It works fine as far as this

C:\blah>rails new test1

C:\blah\test1>rails server

I edit application_controller.rb

I add a function called hello

def hello
   render plain: "aasdf"
end

I edit the routes.rb file

I add this line into the existing  procedure within routes.rb   root 'application#hello'

I access 127.0.0.1:3000/    and it shows  aasdf  

So that's all fine

But here's the problem

If I edit application_controller.rb and change that line from  render plain: "aasdf"   into  render text: "hello world!"   then it doesn't work. Though https://www.railstutorial.org/book/static_pages   suggests using  render text: "hello world!".   in the application controller hello procedure.
i.e.

def hello
   render text: "hello world!"
end


I get the error  "

Missing template application/hello with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :jbuilder]}. Searched in: * "C:/blah/test1/app/views""


And if I change it to one suggestion regarding that kind of error, that I saw online, the suggesetion is to add a parameter of content_type: 'text/plain'  i.e. 

def hello
   render text: "hello world!", content_type: 'text/plain'
end

Then I get the same error

Where am I going wrong here?

Thanks

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/eb8a4956-0925-4085-aefc-cb13eedecd0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/489BD886-12FE-4B9F-A91F-AD98F22C962F%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Problem using render text in basic rails application

Robert Phillips
On Sunday, 7 January 2018 22:34:10 UTC, Phil wrote:

render text: is deprecated.  Stick with render plain: .


Phil


Thanks

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a57cc732-182d-49e4-8584-10e87c209e7f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.