Forum: Ruby on Rails Stylesheets not being recognized

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.
4bef38e99807c7c54b98288c33f8607e?d=identicon&s=25 Steve (Guest)
on 2006-06-01 20:19
I am a newbie, but have worked through 4 or 5 tutorials.  I am using
InstantRails.  The problem is that I cannot determine how the style is
being included.  I have modified the stylesheet from
/public/stylesheets/, even removed it.  All to no avail.  The inline
<style>...</style> code is still being included from somwhere.  Where?
What am I missing?

thanks,
steve
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-06-01 20:46
(Received via mailing list)
Hi Steve,

Steve wrote:

> I cannot determine how the style is
> being included.

If you're generating scaffold code, you'll find the stylesheet linked by
name in your layout file.

> I have modified the stylesheet from
> /public/stylesheets/, even removed it.
>  All to no avail.

What exactly do you mean "to no avail"?  If you've deleted all the
stylesheets in /public/stylesheets, what is it you're seeing that makes
you
sure _any_ style is being applied?

> The inline <style>...</style> code is still
> being included from somwhere.

What do you mean by "inline"?  If, in fact, you've got <style> tags in
your
code, that styling will over-ride any external stylesheet as it's
supposed
to according to the W3C standard.

Sorry I can't help more at this point.  More info needed.

Best regards,
Bill
4bef38e99807c7c54b98288c33f8607e?d=identicon&s=25 Steve (Guest)
on 2006-06-01 22:09
Hi Bill, nice to hear from you again...

> If you're generating scaffold code, you'll find the stylesheet linked by
> name in your layout file.

Yes, I generated scaffold code.  I have an app, contact, based on the
"Fast-track your Web apps with Ruby on Rails" by David Mertz IBM
article.

>> I have modified the stylesheet from
>> /public/stylesheets/, even removed it.
>>  All to no avail.

There is no effect on rendering no matter what I do with the
/views/layouts/contacts.rhtml file

Viz below: no style argument:

<html>
<head>
<title>Contacts: <%= controller.action_name %></title>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<%= @content_for_layout %>
</body>
</html>

Nevertheless, the following is rendered into the /contact/ request
result:

...
<html>
<head>
  <title>Scaffolding</title>
  <style>
    body { background-color: #fff; color: #333; }

    body, p, ol, ul, td {
      font-family: verdana, arial, helvetica, sans-serif;
      font-size:   13px;
      line-height: 18px;
    }
...


> What exactly do you mean "to no avail"?  If you've deleted all the
> stylesheets in /public/stylesheets, what is it you're seeing that makes
> you
> sure _any_ style is being applied?

There is no affect on the rendering style, no matter what I do.  I also
placed my own css code into the default style sheet (contact.css) and it
had no affect on the rendering.

By removing the <style>...</style> code from between the <head> tags in
the generated html page, and viewing in browser, it renders with default
browser style (no css style) and the difference is obvious.

>> The inline <style>...</style> code is still
>> being included from somwhere.
>
> What do you mean by "inline"?  If, in fact, you've got <style> tags in
> your
> code, that styling will over-ride any external stylesheet as it's
> supposed
> to according to the W3C standard.

That is correct and what I would expect.  That's why I am flamoozled in
trying to figure out where/how this <head><style>...</style></head> code
is inserted into the request result, since I want to modify it, and when
I make the modifications they have no effect.  The 'original' style code
continues to render into the head section, overriding any possible
changes I make in the 'global' css, or even deleting it.  And not
referencing it in the layout.

Hope this clarifies the issue!

regards,
Steve
E25296bf52723dc37bc462271eb02d2d?d=identicon&s=25 Jason Pfeifer (jpfeifer)
on 2006-06-01 22:19
That sounds really strange...

My first guess in listening would be to ask: is the stylesheet cached
maybe?
and are you actually generating the scaffolds or are you declaring a
runtime scaffold?  ( scaffold :model )

More than anything this has got to be a simple quirk or something, I've
never had any problems with stylesheets at all.  Are you using an IDE?
4bef38e99807c7c54b98288c33f8607e?d=identicon&s=25 Steve (Guest)
on 2006-06-01 22:47
Jason Pfeifer wrote:
> That sounds really strange...
>
> My first guess in listening would be to ask: is the stylesheet cached
> maybe?
> and are you actually generating the scaffolds or are you declaring a
> runtime scaffold?  ( scaffold :model )
>
> More than anything this has got to be a simple quirk or something, I've
> never had any problems with stylesheets at all.  Are you using an IDE?

Yes, indeed.  I did think of caching issue right off, and cleared all
cache, even restarted the app.

Actually generating the scaffolds via 'ruby script/generate scaffold
Contact'.

for example:
<h1>Listing contacts</h1>
<table>
<tr><% for column in Contact.content_columns %>
<th><%= column.human_name %></th>
<% end %>
</tr>
<% for contact in @contacts %><tr>
<% for column in Contact.content_columns %><td><%=h
contact.send(column.name) %></td><% end %><td><%= link_to 'Show',
:action => 'show', :id => contact %></td><td><%= link_to 'Edit', :action
=> 'edit', :id => contact %></td><td><%= link_to 'Destroy', { :action =>
'destroy', :id => contact }, :confirm => 'Are you sure?' %></td></tr>
<% end %>
</table>
<%= link_to 'Previous page', { :page => @contact_pages.current.previous
} if @contact_pages.current.previous %><%= link_to 'Next page', { :page
=> @contact_pages.current.next } if @contact_pages.current.next %>
<br /><%= link_to 'New contact', :action => 'new' %>


In fact, if you look at the article in
http://www-128.ibm.com/developerworks/linux/librar...

=> search for the heading 'Creating customizable content'

This is where I am de-railed:  a few paragraphs down we see:

"Now there's a bit more to work with, so try modifying a few things.
(Notice that this code has gone back to the plural form contacts, for
reasons not clear to me; we need to accept it for now.) Try changing a
few colors and fonts in the CSS:"

This is what I was doing, and NOTHING!  I referenced InstantRails
because I was suspicious that perhaps something in this platform is
'managing' the style include somehow.

Don't get me wrong:  I love the InstantRails platform. It's completely
portable, doesn't interfere with anything else running on the local, and
allows you to easily poke around and learn.

But I'm stumped on this style issue...
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-06-01 23:16
(Received via mailing list)
Steve wrote:

> Hi Bill, nice to hear from you again...

Thanks, Steve.  Likewise.

> There is no effect on rendering no matter what
> I do with the /views/layouts/contacts.rhtml file
>
> Viz below: no style argument:
>
> <html>
> <head>
> <title>Contacts: <%= controller.action_name %></title>

Scaffolding (i.e., ruby script\generate scaffold Model Controller)
generates
a line that's missing here (<%= stylesheet_link_tag 'scaffold' %>).
That's
what tell's Rails what stylesheet to use.  Did you remove it?

> Nevertheless, the following is rendered into the /contact/ request
> result:
> ...
> <html>
> <head>
>  <title>Scaffolding</title>

This looks like trouble.  The title *should* be (per the line in
contacts.rhtml) something that starts with 'Contacts: ", this is
definitely
where I'd be digging.  Do you have a method named 'Scaffolding' in
contacts_controller.rb?  If so, I'd recommend renaming it and see what
happens.  I would not be a bit surprised to find that its use as a
method
name caused unexpected results.  OTOH, I did a little sandbox test
myself
and couldn't reproduce your results.

> <style>
>    body { background-color: #fff; color: #333; }
>
>    body, p, ol, ul, td {
      font-family: verdana, arial, helvetica, sans-serif;
      font-size:   13px;
      line-height: 18px;
    }
...
Interesting.  This is also the content of scaffold.css.

> I also placed my own css code into the default
> style sheet (contact.css)

I'm not sure what you mean by 'default' here.  The style sheet Rails
generates / uses by default is called 'scaffold.css'.  You can replace
and/or augment that (i.e., you can specify a different style sheet or
more
than one style sheet) in the stylesheet_link_tag, but since the code
above
doesn't have a stylesheet_link_tag ...

As far as that goes, I have no idea how, without explicitly trying to,
you're getting style tags embedded in your html page.  I'm not familiar
with
the tutorial you're working on but... any chance you've got a
@content_for_header variable anywhere in the code?

It's an interesting problem (but then, _anything's_ interesting if it's
not
happening to one's self ;-) ).  Hope you'll post back with more info /
your
findings.  Sorry I can't be more help at the moment.

Best regards,
Bill
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-06-01 23:51
(Received via mailing list)
Steve wrote:

> (Notice that this code has gone back to the plural form
> contacts, for reasons not clear to me;

Just as an FYI, the reason for the contacts_controller and contracts
view
directory is that he didn't specify a controller name in his scaffold
command.
4bef38e99807c7c54b98288c33f8607e?d=identicon&s=25 Steve (Guest)
on 2006-06-02 01:11
Bill Walton wrote:
> Steve wrote:
>
>> Hi Bill, nice to hear from you again...
>
> Thanks, Steve.  Likewise.
>
>> There is no effect on rendering no matter what
>> I do with the /views/layouts/contacts.rhtml file
>>
>> Viz below: no style argument:
>>
>> <html>
>> <head>
>> <title>Contacts: <%= controller.action_name %></title>
>
> Scaffolding (i.e., ruby script\generate scaffold Model Controller)
> generates
> a line that's missing here (<%= stylesheet_link_tag 'scaffold' %>).
> That's
> what tell's Rails what stylesheet to use.  Did you remove it?

Yes, indeed.  I removed it in order to force at least *no* style
application.  Surprise.  Even without the argument to scaffold.css it
still renders the <style> code into the head of the returned html.

Yes.  scaffold.css is the 'global' css file I mistakenly referred to as
contacts.css

I'll check into the other items you mention at the earliest opportunity.
Probably not today.


I really appreciate you walking through this issue.  I continue to
learn.

Will get to the bottom of it...

steve
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-06-02 02:59
(Received via mailing list)
Steve wrote:

> contacts.css
Thanks.  It's the damn details ;-)

> I really appreciate you walking through this issue.  I continue to
> learn.

Thank you for hanging in there!!!  We're all still learning!!!

> Will get to the bottom of it...

Definitely looking forward to it.  Like I said before...  if your view
file
really says <title>Contacts: <%= controller.action_name %></title>, then
there's *no* way you should be getting the <title>Scaffolding</title>
resulting html.  Totally wierd.

Best regards,
Bill
4bef38e99807c7c54b98288c33f8607e?d=identicon&s=25 Guest - Steve Ball (Guest)
on 2006-06-03 04:03
Solved.  Well, it definitely had to do with the 'create a view' behavior
of the scaffold script (which the author mentioned and you commented
upon):  "Just as an FYI, the reason for the contacts_controller and
contracts [sic] view directory is that he didn't specify a controller
name in his scaffold command."

The bottom line was I was using http://myapp/contact/ to request the
page, whereas there was now an http://myapp/contacts/ [plural] folder in
views, with the style pointer to scaffold.css.  So I was making all
these mods to the scaffold.css, but the code was being generated on the
fly based on my request to the earlier created views/contact (via
script/generate controller contact).

Confusing yes.  It got me even when the phenomena was pointed out in the
article.  However, it provided a path to understanding.  Now I am going
to *specify* the controller name and manage this correctly.

This was just a minor stopsign, and I thank you for your help and
patience.

On to the next stoplight... :)

best,
steve

Bill Walton wrote:
> Steve wrote:
>
>> contacts.css
> Thanks.  It's the damn details ;-)
>
>> I really appreciate you walking through this issue.  I continue to
>> learn.
>
> Thank you for hanging in there!!!  We're all still learning!!!
>
>> Will get to the bottom of it...
>
> Definitely looking forward to it.  Like I said before...  if your view
> file
> really says <title>Contacts: <%= controller.action_name %></title>, then
> there's *no* way you should be getting the <title>Scaffolding</title>
> resulting html.  Totally wierd.
>
> Best regards,
> Bill
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-06-03 17:37
(Received via mailing list)
Steve Ball wrote:

> Solved.

Excellent!  And thanks for the update.  It's really good form, IMO, when
folks take the time to post here to document the solution they've found.
Makes it easier for the next newbie.  That's what it's is all about.

> On to the next stoplight... :)

Onward and upward!!!

Best regards,
Bill
This topic is locked and can not be replied to.