Ruby on Rails Friday, April 27, 2012

On Apr 27, 2012, at 4:52 PM, Jeff Kyzer wrote:

> Hi
>
> I started working with the book Ruby on Rails3 about 2 months ago.
> Going through the sample app was fun and interesting. I had to put it
> down for a couple of weeks. When I came back to it, I figured that I
> would just start over. So from the very first part - the addition of
> a title - new stuff is added to my page, and I have no idea where this
> is coming from. Here is an example.
>
> The Home.html.erb file
>
>
> <!DOCTYPE html>
> <html>
> <head>
> <title>Ruby on Rails Tutorial Sample App | Home</title>
> </head>
>
> <body>
> <h1>Sample App</h1>
> <p>
> This is the home page for the
> <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
> sample application
> </p>
> </body>
> </html>
>
>
> Very simple, but when I bring up the view source file of the localhost:
> 3000/pages/home I get the following. Where is all that extra stuff
> come from on top and how do I get rid of it?

That's coming from the /views/layouts/application.html.erb file. This is how Rails templates usually render. You don't want to get rid of that file, only edit it to remove the extra bits you don't need. Remember though -- you will need the JavaScript stuff if you expect your forms to work, since you won't be able to send a PUT or DELETE request without it.

But more importantly, your home.html.erb should very definitely only be this part:

<h1>Sample App</h1>
<p>
This is the home page for the
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
sample application
</p>

Otherwise you will either have to override the normal (convention-based) Rails rendering to remove the template option from every render, or you'll end up with a page-within-a-page monstrosity such as you have now.

Walter

>
> Thanks
>
>
> <!DOCTYPE html>
> <html>
> <head>
> <title>SampleApp</title>
> <link href="/assets/application.css?body=1" media="all"
> rel="stylesheet" type="text/css" />
> <link href="/assets/pages.css?body=1" media="all" rel="stylesheet"
> type="text/css" />
> <script src="/assets/jquery.js?body=1" type="text/javascript"></
> script>
> <script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></
> script>
> <script src="/assets/pages.js?body=1" type="text/javascript"></script>
> <script src="/assets/application.js?body=1" type="text/javascript"></
> script>
> <meta content="authenticity_token" name="csrf-param" />
> <meta content="XJBbNLStkGBebtN4iJoR1EzvJWX8XA1YgJamnb3EfDc="
> name="csrf-token" />
> </head>
> <body>
>
> <!DOCTYPE html>
> <html>
> <head>
> <title>Ruby on Rails Tutorial Sample App \ About</title>
> </head>
>
> <body>
> <h1>About Us</h1>
> <p>
> <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
> is a project to make a book and screencaste to teach web
> development
> with <a href="http://rubyonrails.org/">Ruby on Rails></a>. This is
> the sample application for the tutorial.
> </p>
> </body>
> </html>
>
> </body>
> </html>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment