Forum: Ruby on Rails how to use templates in ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1740127afd5cb6d06475ea4ffde85766?d=identicon&s=25 Paul Na (paulie)
on 2009-03-03 23:41
hi all,

I have created links ie:-

/articles
/news

and i looked on a site and it said creating a .rhtml file in the
app/views/articles news etc but when i created news.rhtml and
articles.rhtml and put it in the folder in the app/views and its still
reading the

class ArticlesController < ApplicationController
      def index
         render :text => "This is the articles page"
      end

end

in the controller and not the .rhtml file

how is this done

many thanks

paul
988320371d9a18f0d50375188e01d54a?d=identicon&s=25 Peter Vandenabeele (Guest)
on 2009-03-04 11:02
(Received via mailing list)
On Tue, Mar 3, 2009 at 11:41 PM, Paul Na
<rails-mailing-list@andreas-s.net> wrote:
> articles.rhtml and put it in the folder in the app/views and its still
>
> how is this done

If I understand correctly, the fact that you call render explicitely
in the controller,
will avoid the "automatic" render of the template in
app/views/articles/index.html.erb

So, I suggest yoiu change as follows:

Controller: ../app/controllers/articles_controller.rb

class ArticlesController < ApplicationController
     def index
       @test_article = "This is a test article"
     end
end

Views: ../app/views/articles/index.html.erb

<p>test of an article <%=h @test_article %></p>

Then go to

htpp://localhost:3000/articles/

HTH,

Peter





>
> many thanks
>
> paul
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>



--
Peter Vandenabeele
gsm: +32-478-27.40.69
e-mail: peter@vandenabeele.com
http://www.linkedin.com/in/petervandenabeele
http://vandenabeele.com
http://twitter.com/peter_v
988320371d9a18f0d50375188e01d54a?d=identicon&s=25 Peter Vandenabeele (Guest)
on 2009-03-04 11:05
(Received via mailing list)
On Wed, Mar 4, 2009 at 11:01 AM, Peter Vandenabeele
<peter.vandenabeele.be@gmail.com> wrote:
> If I understand correctly, the fact that you call render explicitely
> in the controller, will avoid the "automatic" render of the template in
> app/views/articles/index.html.erb

Forgot to explain this. Only if you did not explicitly call 'render'
or 'redirect_to'
Rails will automatically call the render function on the corresponding
location
in the ../app/views/ directory.

Peter
1740127afd5cb6d06475ea4ffde85766?d=identicon&s=25 Paul Na (paulie)
on 2009-03-04 12:02
Peter Vandenabeele wrote:
> On Wed, Mar 4, 2009 at 11:01 AM, Peter Vandenabeele
> <peter.vandenabeele.be@gmail.com> wrote:
>> If I understand correctly, the fact that you call render explicitely
>> in the controller, will avoid the "automatic" render of the template in
>> app/views/articles/index.html.erb
>
> Forgot to explain this. Only if you did not explicitly call 'render'
> or 'redirect_to'
> Rails will automatically call the render function on the corresponding
> location
> in the ../app/views/ directory.
>
> Peter

Hi peter

Thanks its working , Im just trying to get my head around it all.

Thanks again

Paul
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2009-03-04 16:12
Paul Na wrote:
> Thanks its working , Im just trying to get my head around it all.

By the way in case you didn't notice, all the cool kids are using the
"html.erb" extension instead of "rhtml" extension for view templates
that render HTML using embedded Ruby (ERB).

I'll leave it as a task for you to discover why html.erb is so cool.
1740127afd5cb6d06475ea4ffde85766?d=identicon&s=25 Paul Na (paulie)
on 2009-03-04 17:24
Robert Walker wrote:
> Paul Na wrote:
>> Thanks its working , Im just trying to get my head around it all.
>
> By the way in case you didn't notice, all the cool kids are using the
> "html.erb" extension instead of "rhtml" extension for view templates
> that render HTML using embedded Ruby (ERB).
>
> I'll leave it as a task for you to discover why html.erb is so cool.

Hi robert

yeh i did come across soething to do with it when trying to load the
news page up and it come back with a error , which i had the news page
as index.rhtml.erb i changed it to index.html.erb then it worked
This topic is locked and can not be replied to.