Help stylesheet_link_tag

I was reading the book “Agile Web D. with Rails 4th Edition”.
In Chapter 11, Iteration C2: Adding a Page Layout
1

  • Pragprog Books Online Store

5 <%= stylesheet_link_tag “scaffold” %>

  • <%= stylesheet_link_tag “depot”, :media => “all” %>
  • <%= javascript_include_tag :defaults %>
  • <%= csrf_meta_tag %>

“stylesheet_link_tag” and “javascript_include_tag” dosn’t work. My
Rails version is 3.2.1. The book was written using Rails 3.0.5.
How to modify stylesheet_link_tag parameters to fit Rails 3.2.1?

My files

[email protected]:~/depot$ ls app/assets/stylesheets/
application.css depot.css products.css.scss store.css.scss
carts.css.scss line_items.css.scss scaffolds.css.scss

[email protected]:~/depot$ ls app/assets/javascripts/
application.js depot.css products.js.coffee
carts.js.coffee line_items.js.coffee store.js.coffee
[email protected]:~/depot$

rails server outputs
Started GET “/assets/scaffold.css” for 127.0.0.1 at 2012-03-01
09:44:21 +0800
Served asset /scaffold.css - 404 Not Found (5ms)

ActionController::RoutingError (No route matches [GET] “/assets/
scaffold.css”):
actionpack (3.2.1) lib/action_dispatch/middleware/
debug_exceptions.rb:21:in call' actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb: 56:incall’
railties (3.2.1) lib/rails/rack/logger.rb:26:in call_app' railties (3.2.1) lib/rails/rack/logger.rb:16:incall’
actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:
22:in call' rack (1.4.1) lib/rack/methodoverride.rb:21:incall’
rack (1.4.1) lib/rack/runtime.rb:17:in call' activesupport (3.2.1) lib/active_support/cache/strategy/ local_cache.rb:72:incall’
rack (1.4.1) lib/rack/lock.rb:15:in call' actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:incall’
railties (3.2.1) lib/rails/engine.rb:479:in call' railties (3.2.1) lib/rails/application.rb:220:incall’
rack (1.4.1) lib/rack/content_length.rb:14:in call' railties (3.2.1) lib/rails/rack/log_tailer.rb:14:incall’
rack (1.4.1) lib/rack/handler/webrick.rb:59:in service' /home/hj/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/ httpserver.rb:138:inservice’
/home/hj/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/
httpserver.rb:94:in run' /home/hj/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb: 191:inblock in start_thread’

Rendered /home/hj/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.1/lib/
action_dispatch/middleware/templates/rescues/routing_error.erb within
rescues/layout (1.2ms)

Started GET “/assets/defaults.js” for 127.0.0.1 at 2012-03-01 09:44:21
+0800
Served asset /defaults.js - 404 Not Found (5ms)

ActionController::RoutingError (No route matches [GET] “/assets/
defaults.js”):
actionpack (3.2.1) lib/action_dispatch/middleware/
debug_exceptions.rb:21:in call' actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb: 56:incall’
railties (3.2.1) lib/rails/rack/logger.rb:26:in call_app' railties (3.2.1) lib/rails/rack/logger.rb:16:incall’
actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:
22:in call' rack (1.4.1) lib/rack/methodoverride.rb:21:incall’
rack (1.4.1) lib/rack/runtime.rb:17:in call' activesupport (3.2.1) lib/active_support/cache/strategy/ local_cache.rb:72:incall’
rack (1.4.1) lib/rack/lock.rb:15:in call' actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:incall’
railties (3.2.1) lib/rails/engine.rb:479:in call' railties (3.2.1) lib/rails/application.rb:220:incall’
rack (1.4.1) lib/rack/content_length.rb:14:in call' railties (3.2.1) lib/rails/rack/log_tailer.rb:14:incall’
rack (1.4.1) lib/rack/handler/webrick.rb:59:in service' /home/hj/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/ httpserver.rb:138:inservice’
/home/hj/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/
httpserver.rb:94:in run' /home/hj/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb: 191:inblock in start_thread’

hj wrote in post #1049623:

I was reading the book “Agile Web D. with Rails 4th Edition”.
In Chapter 11, Iteration C2: Adding a Page Layout

“stylesheet_link_tag” and “javascript_include_tag” dosn’t work. My
Rails version is 3.2.1. The book was written using Rails 3.0.5.
How to modify stylesheet_link_tag parameters to fit Rails 3.2.1?

First of all I would suggest that if you’re learning Rails from a book,
then install the version of Rails that the book is using. It will save
you a lot of headaches like this as you learn. Once you have a good
handle on Rails then investigate the changes made in subsequent
releases. There are release notes for each version that will explain
things.

However, the easiest way to discover things like this is to generate a
new project. Then generate a scaffold and go into the files and see what
they use.

Example:

$ rails new demo
$ cd demo
$ rails g scaffold Person name:string

app/views/layouts/application.html.erb

Demo <%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %>

<%= yield %>

Keep in mind though that Rails 3.1+ is going to use the new asset
pipeline, which your rails book will know nothing about. So if you want
to continue to use Rails 3.2.1 with your book you’ll first have to know
about what has changed since 3.0.5.

Again I strongly recommend you roll back to Rails 3.0.5 while learning
from that book.

gem install rails --version="~> 3.0"

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs