rails asset pipeline images and css not displaying - ruby-on-rails

I am new to rails and am following the examples in Michael Hartl. I am having an issue in chapter 5 (https://www.railstutorial.org/book/filling_in_the_layout). I have followed the michaels instructions but I am not seeing images and my css is not displaying.
I am using ruby Rails 5.0.1 with ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
I added michaels html/code to my home.html.erb
<% provide(:title, "Home") %>
<div class="center jumbotron">
<h1>Welcome to the Sample App</h1>
<h2>
This is the home page for the
Ruby on Rails Tutorial
sample application.
</h2>
<%= link_to "Sign up now!", '#', class: "btn btn-lg btn-primary" %>
</div>
<%= link_to image_tag("rails.png", alt: "Rails logo"),
'http://rubyonrails.org/' %>
<br/><br/>
<%= link_to image_tag("bunratty.png", alt: "Bunratty"),
'http://rubyonrails.org/' %>
<%= link_to image_tag("kitten.png", alt: "Kitten"),
'http://rubyonrails.org/' %>
<%= image_tag image_url('rails.png') %>
<%= image_tag image_path('rails.png') %>
Display using html
<img src="/public/rails.png" alt="rails logo"/>
I copied the rails.png image into app/assets/images/ directory but when I run the application the image is not displayed only the alt tag is displayed.
I also added bootstrap as per the instructions and it isnt working either.
gemfile extract
source 'https://rubygems.org'
gem 'rails', '5.0.1'
gem 'bootstrap-sass', '3.3.6'
I ran bundle install and can see it is installed using a bundle show
$ bundle show
Gems included by the bundle:
* actioncable (5.0.1)
* actionmailer (5.0.1)
* actionpack (5.0.1)
* actionview (5.0.1)
* activejob (5.0.1)
* activemodel (5.0.1)
* activerecord (5.0.1)
* activesupport (5.0.1)
* ansi (1.5.0)
* arel (7.1.4)
* autoprefixer-rails (6.7.5)
* bootstrap-sass (3.3.6)
* builder (3.2.3)
* bundler (1.13.7)
* coderay (1.1.1)
* coffee-rails (4.2.1)
* coffee-script (2.4.1)
* coffee-script-source (1.12.2)
* concurrent-ruby (1.0.4)
* debug_inspector (0.0.2)
* erubis (2.7.0)
* execjs (2.7.0)
* ffi (1.9.17)
* formatador (0.2.5)
* globalid (0.3.7)
* guard (2.13.0)
* guard-compat (1.2.1)
* guard-minitest (2.4.4)
* i18n (0.8.0)
* jbuilder (2.4.1)
* jquery-rails (4.1.1)
* listen (3.0.8)
* loofah (2.0.3)
* lumberjack (1.0.11)
* mail (2.6.4)
* method_source (0.8.2)
* mime-types (3.1)
* mime-types-data (3.2016.0521)
* mini_portile2 (2.1.0)
* minitest (5.10.1)
* minitest-reporters (1.1.9)
* multi_json (1.12.1)
* nenv (0.3.0)
* nio4r (1.2.1)
* nokogiri (1.7.0.1)
* notiffany (0.1.1)
* pg (0.18.4)
* pry (0.10.4)
* puma (3.4.0)
* rack (2.0.1)
* rack-test (0.6.3)
* rails (5.0.1)
* rails-controller-testing (0.1.1)
* rails-dom-testing (2.0.2)
* rails-html-sanitizer (1.0.3)
* railties (5.0.1)
* rake (12.0.0)
* rb-fsevent (0.9.8)
* rb-inotify (0.9.8)
* ruby-progressbar (1.8.1)
* sass (3.4.23)
* sass-rails (5.0.6)
* shellany (0.0.1)
* slop (3.6.0)
* spring (1.7.2)
* spring-watcher-listen (2.0.0)
* sprockets (3.7.1)
* sprockets-rails (3.2.0)
* sqlite3 (1.3.12)
* thor (0.19.4)
* thread_safe (0.3.5)
* tilt (2.0.6)
* turbolinks (5.0.1)
* turbolinks-source (5.0.0)
* tzinfo (1.2.2)
* tzinfo-data (1.2016.10)
* uglifier (3.0.0)
* web-console (3.1.1)
* websocket-driver (0.6.5)
* websocket-extensions (0.1.2)
I added a custom.scss file to app\assets\stylesheets
#import "bootstrap-sprockets";
#import "bootstrap";
/* universal */
body {
padding-top: 60px;
background-color:lime;
}
section {
overflow: auto;
}
textarea {
resize: vertical;
}
.center {
text-align: center;
}
.center h1 {
margin-bottom: 10px;
}
Is this a problem with the assets pipeline since neither the css or images are displaying.
I have tried putting the image in the public directory, the public/images directory, the app/assets directory but it isn't display in any of these.
I have tried using a different image incase the image is corrupted
I have tried using creating a new project
Any help would be greatly appreciated.
Thank your for coming back to me. Some extra information as requested:
I don't have an application.scss file, just an application.css file with the following content:
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*/
The html generated is as follows:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" media="all" href="/stylesheets/default.css" data-turbolinks-track="reload" />
<script src="/javascripts/default.js" data-turbolinks-track="reload"></script>
<title>Home | Ruby on Rails Tutorial</title>
<meta name="csrf-param" content="authenticity_token" />
<meta name="csrf-token" content="SogDGi5kvIl13JKu57VqH0phQ/1pSw+tKuVAmvTVuQITclDhVvKLJNwHJJzcOa0qUlOhJ8cmRsBx9rUCINA+TQ==" />
</head>
<body>
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<a id="logo" href="#">sample app</a>
<nav>
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li>Help</li>
<li>About Us</li>
</ul>
</nav>
</div>
</header>
<div class="container">
<div class="center jumbotron">
<h1>Welcome to the Sample App</h1>
<h2>
This is the home page for the
Ruby on Rails Tutorial
sample application.
</h2>
<a class="btn btn-lg btn-primary" href="#">Sign up now!</a>
</div>
<img alt="Rails logo" src="/images/rails.png" />
<br/><br/>
<img alt="Bunratty" src="/images/bunratty.png" />
<img alt="Kitten" src="/images/kitten.png" />
<img src="http://localhost:3000/images/rails.png" alt="Rails" />
<img src="/images/rails.png" alt="Rails" />
Display using html
<img src="/public/rails.png" alt="rails logo"/>
<img src="/public/rails.png" alt="rails logo"/>
<img src="http://localhost:3000/public/rails.png" alt="rails logo"/>
<br/>
http://localhost:3000/images/rails.png
</div>
</body>
</html>
Accessing localhost:3000/assets/rails.png in a browser gives the following error.
No route matches [GET] "/assets/rails.png"
Rails.root: c:/rails/static_app

Assuming your action that generates the following views has a controller calling the layout app/views/layouts/application.html.erb as shown on chapter 5, then you need to require your custom.scss on your application.scss
your controller
class ApplicationController < ActionController::Base
layout 'application'
def index
end
end
your application.scss
/*
= require_self
*/
#import "custom.scss";
The index action is just an example, if you named your view home.html.erb I can imagine you are pointing to a home action inside your controller

Related

Rails 5 upgrade and font awesome relative path not found in s3

Post rails upgrade from rails 4 too rails 5 font awesome loading path is not correct for more understanding
My Application.css path(correct path)
https://s3_domain/s3_bucket_name/project_name/assets/admin-fingerprint.css
Request Method: GET
Rendered 403 font awesome
https://s3_domain/assets/fontawesome-webfont-fingerprint.woff2
Request Method: GET
Ideally correct path should be->
https://s3_domain/s3_bucket_name/project_name/assets/fontawesome-webfont-fingerprint.woff2
Request Method: GET
related gems in my project
* autoprefixer-rails (10.4.7.0)
* font-awesome-rails (4.7.0.8)
* jquery-fileupload-rails (1.0.0)
* jquery-minicolors-rails (2.2.6.2)
* jquery-rails (4.5.0)
* minitest-rails (3.0.0)
* pry-rails (0.3.9)
* rails (5.1.0)
* sass-rails (6.0.0)
* sassc (2.4.0)
* sassc-rails (2.1.2)
* slim-rails (3.5.1)
* sprockets-rails (3.2.2)

Rake task NoMethodError: undefined method `task' for main:Object

I have this code which works fine (!!! without the first line "task..."!!!) in console. It creates events in DB. However no luck when running the rake (rake fetch_ttt):
task :fetch_ttt => :environment do
require 'nokogiri'
require 'open-uri'
url = "http://www.example.com"
doc = Nokogiri::HTML(open(url))
doc.css("#eventrow").each do |item|
unless Event.find_by_name(item.at_css("a").text).present?
Event.create(
:start_time => item.at_css("#eventdate").text,
:name => item.at_css("a").text,
:url => item.at_css("a")[:href]
)
end
end
end
This is the trace (not much in dry run neither):
** Invoke fetch_ttt (first_time)
** Invoke environment (first_time)
** Execute (dry run) environment
** Execute (dry run) fetch_ttt
It has been fine couple hours ago. Since then I did a "bundle update", made some DB migrations, edited associations. I tried rolling back migrations and removed model association changes with no luck. I suspect the gems.
Below the 3 gems I rolled back to the previous versions to see if they are responsible but not. And the full diff.
old ones:
gem 'rake', '10.5.0'
gem 'http', '0.9.8'
gem 'ipaddress', '0.8.2'
full diff:
- bcrypt (3.1.10)
+ bcrypt (3.1.11)
- carrierwave (0.10.0)
+ carrierwave (0.11.2)
+ mimemagic (>= 0.3.0)
- concurrent-ruby (1.0.0)
+ concurrent-ruby (1.0.2)
- devise (3.5.6)
+ devise (4.1.1)
- railties (>= 3.2.6, < 5)
+ railties (>= 4.1.0, < 5.1)
- thread_safe (~> 0.1)
- domain_name (0.5.20160128)
+ domain_name (0.5.20160310)
- excon (0.45.4)
+ excon (0.49.0)
- excon (~> 0.45)
+ excon (~> 0.49)
****lots of stuff related to "fog" gem
- http (0.9.8)
+ http (0.9.9)
- ipaddress (0.8.2)
+ ipaddress (0.8.3)
- mime-types (2.99)
- mini_magick (4.4.0)
+ mime-types (2.99.1)
+ mimemagic (0.3.1)
+ mini_magick (4.5.1)
mini_portile2 (2.0.0)
- minitest (5.8.4)
- multi_json (1.11.2)
+ minitest (5.9.0)
+ multi_json (1.12.0)
- rails_stdout_logging (0.0.4)
+ rails_stdout_logging (0.0.5)
- responders (2.1.1)
+ responders (2.2.0)
- sprockets (3.5.2)
+ sprockets (3.6.0)
- sprockets-rails (3.0.1)
+ sprockets-rails (3.0.4)
- tilt (2.0.2)
+ tilt (2.0.4)
Rails 4.2.5, Ruby 2.1.4, I am on C9 IDE. But doesn't work on heroku neither.
UPDATE
reverted back to rake 10.5.0 (and did grep rake Gemfile.lock) now in the console I only get:
<Rake::Task fetch_ttt => [environment]>
scraping doesn't run at all :(
I don't think there's enough info here to give a definitive answer, but I would start by investigating the root cause for why it isn't working on heroku.
For example, does the rake task run at all? How do you know?
If so, do heroku run rails c and try doing the sequence of code yourself. Inspect the database records before and after you expect a chance. What happened?
If it didn't run, what type of output did you get? heroku logs can also be helpful.
One other little tip, it's possible to use byebug with heroku logs -t. Although I only recommend this in your staging environment and only if you're willing to clean up the git history afterwards.
In short, my answer is I would solve it by debugging more directly. Hope this helps.
outcommented
#require 'nokogiri'
#require 'open-uri'
and now it works. Even with rake 11.1.2

Permission Denied error when uploading to local filesystem via paperclip gem

I've used paperclip in the past with AWS S3 storage, but with this project I'm trying to reduce external dependencies. I'd like to save uploaded images to the public/assets directory, for immediate use (skirting asset pipeline). Here's the error I'm getting when it tries to save:
Errno::EPERM in PostsController#update
Operation not permitted - /usr/local/src/project_name/public/assets/
...
app/controllers/posts_controller.rb:43:in `update'
I've chmod'ed the directories to 755, as suggested in an existing Stack Overflow solution. That shouldn't even matter though, because thin (my web server) is running as root (via sudo) so that I can bind to 443 (HTTPS). I don't understand why would there even be a permission error for root. What am I not getting? Is the file being uploaded by the user under an anonymous public account, or is the application server saving it as root?
Additional info:
Environment: Development
Operating System: OS X 10.9.3
Ruby version:
MRI ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
Gem versions:
Gems included by the bundle:
* actionmailer (4.0.3)
* actionpack (4.0.3)
* activemodel (4.0.3)
* activerecord (4.0.3)
* activerecord-deprecated_finders (1.0.3)
* activesupport (4.0.3)
* acts-as-taggable-on (3.2.6)
* arel (4.0.2)
* atomic (1.1.15)
* bcrypt (3.1.7)
* bcrypt-ruby (3.1.5)
* builder (3.1.4)
* bundler (1.5.3)
* climate_control (0.0.3)
* cocaine (0.5.3)
* coffee-rails (4.0.1)
* coffee-script (2.2.0)
* coffee-script-source (1.7.0)
* daemons (1.1.9)
* epiceditor (0.2.2.1)
* erubis (2.7.0)
* eventmachine (1.0.3)
* execjs (2.0.2)
* faraday (0.9.0)
* friendly_id (5.0.4)
* haml (4.0.5)
* haml-rails (0.5.3)
* hike (1.2.3)
* i18n (0.6.9)
* jquery-rails (3.1.0)
* json (1.8.1)
* jwt (1.0.0)
* mail (2.5.4)
* mime-types (1.25.1)
* minitest (4.7.5)
* multi_json (1.8.4)
* multi_xml (0.5.5)
* multipart-post (2.0.0)
* oauth (0.4.7)
* oauth2 (0.9.4)
* paperclip (4.1.1)
* polyglot (0.3.4)
* rack (1.5.2)
* rack-test (0.6.2)
* rails (4.0.3)
* railties (4.0.3)
* rake (10.1.1)
* rdiscount (2.1.7.1)
* sass (3.2.14)
* sass-rails (4.0.1)
* sorcery (0.8.5)
* sprockets (2.11.0)
* sprockets-rails (2.0.1)
* sqlite3 (1.3.9)
* thin (1.6.2)
* thor (0.18.1)
* thread_safe (0.2.0)
* tilt (1.4.1)
* treetop (1.4.15)
* tzinfo (0.3.38)
* uglifier (2.4.0)
File permissions (via ls -la public):
drwxr-xr-x 9 proto admin 306 Jul 6 15:16 .
drwxr-xr-x 23 proto admin 782 Mar 28 06:24 assets
Server Daemon (via ps aux | grep [t]hin):
root 2650 0.0 0.9 2513704 79120 ?? S 3:43PM 0:07.81 thin server (0.0.0.0:443)
Post model:
class Post < ActiveRecord::Base
# Relationships
extend FriendlyId
friendly_id :title, use: [:slugged, :history]
has_attached_file :photo,
path: ':rails_root/public/assets/',
url: ':basename.:extension'
belongs_to :author
# Validations
validates_presence_of :title, :body, :author_id, :slug
validates_uniqueness_of :slug
validates_attachment_content_type :photo, content_type: /\Aimage\/.*\Z/
# Overriding this friendly method to update slug when title changes
def should_generate_new_friendly_id?
slug.blank? || title_changed?
end
end
Update action:
def update
#data = {
title: params[:post][:title],
body: params[:post][:body],
photo: params[:post][:photo]
}
if #post.update! #data
redirect_to #post
else
render :edit, layout: 'layouts/admin'
end
end
Form partial:
= form_for post, html: { multipart: true } do |f|
= f.text_field :title, placeholder: 'Title'
%br
= f.text_area :body, class: 'hidden'
#epiceditor
%br
= f.submit 'Save', class: 'button'
- unless post.new_record?
= link_to 'Delete', post, method: 'delete', class: 'button'
= f.file_field :photo, class: 'upload'
- unless post.photo.nil?
= link_to post.photo.url, post.photo.url
This is too long to write as a comment, but you could use other port than 443, which the root will redirect to from port 443, using, let's say, iptables.
$ sudo iptables -t nat -I PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443
Then you can start your server normally, as rails user, on port 8443
This is of course if you want to do so.
Regarding the comment/question I've asked to your question, I'm not familiar with thin server, but I would consider the case where the application is running as rails user (proton?) and the frontend web server as root. In that case, root owned assets folder will probably not writeable for rails user....
Change the permissions on public folder to 775.
Update
You might find your solution here: Errno::EPERM (Operation not permitted FILE_PATH) when uploading image with Rails, Carrierwave, Amazon EC2
Looks like you might need to change the owner of public/assets to root (or whichever user the application is running as).

CoffeeScript working strangely with Rails 4

I cannot get CoffeeScript working with Rails. This is the first time I'm using CoffeeScript and I'm also fairly new with Rails too, so I don't know how to make this simple CoffeeScript function to work in the right way. Below is my people.js.coffee file at app/assets/javascript directory.
myFunction = ->
alert "test"
The alert “test” message only shows up when I load the page (app/views/people.html.erb and _form.html.erb partial); not when I click the below button in the form:
<%= submit_tag "Test CoffeeScript", :type => 'button',
:id => 'coffeeScript', :onclick => 'myFunction()' %>
I don't know why this strange behaviour is happening. Why :onclick is not working? The generated source code for the button should be ok:
<input id="coffeeScript" name="commit" onclick="myFunction()"
type="button" value="Test CoffeeScript" />
Below is my application.js file at app/assets/javascript.
...
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
My Ruby version is 2.1.0
Here are some values when I ran bundle show command:
coffee-rails (4.0.1)
coffee-script (2.2.0)
coffee-script-source (1.7.0)
jbuilder (1.5.3)
jquery-rails (3.1.0)
rails (4.0.2)
railties (4.0.2)
sass (3.2.19)
sass-rails (4.0.3)
sprockets (2.11.0)
sprockets-rails (2.0.1)
turbolinks (2.2.2)
My JavaScript files are working ok; I tried similar type of function in JavaScript and it was ok.
It's because the function is in another scope. You can do it either with unobtrusive jquery.
$ ->
myFunction = ->
alert("test")
$("#coffeeScript").on "click", ->
myFunction()
And remove the onclick handler from
<%= submit_tag "Test CoffeeScript", type: 'button', id: 'coffeeScript' %>
or...
root = exports ? this
root.myFunction = () -> alert("test!")
I'd recommend the first one, but that is just my opinion though. Also, you have to be very careful about indentation in CoffeeScript, it works a lot like Python, whitespace matters.
An explanation on scopes and js/coffee is here How do I define global variables in CoffeeScript?

relative paths for accessing rails assets

I'm stuck! xD I've been working on a Rails project and am having trouble accessing my assets using relative paths. A friend of mine is working on the html/css side of things while I'm handling the controllers and models. My friend recently gave me a batch of files structured in the following way:
app/assets/images/*.jpg
app/assets/stylesheets/*.css
app/assets/javascripts/*.js
app/assets/fonts/*.* (+some more css files in here)
Within my app/views/layouts directory, I have a layout named final.html.erb which is used for my entire webapp. I also have 1 page(html body content) that I'm trying to render with this layout in app/views/pages named final_page.html.erb ... the necessary routing is in place for the page to load; however, it only loads the context of the final_page.html.erb (no images, styling, or fonts). When I go to the console and type "rails server" and visit localhost:3000, the page shows up ... naked lol. The console outputs the following:
Started GET "/" for 127.0.0.1 at 2012-07-28 21:15:02 -0700
Connecting to database specified by database.yml
Processing by PagesController#final_page as HTML
Rendered pages/final_page.html.erb within layouts/final (8.4ms)
Completed 200 OK in 82ms (Views: 81.0ms | ActiveRecord: 0.0ms)
Started GET "/assets/stylesheets/style.css" for 127.0.0.1 at 2012-07-28 21:15:04 -0700
ActionController::RoutingError (No route matches [GET] "/assets/stylesheets/style.css"):
actionpack (3.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.6) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.6) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.6) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.6) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.6) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.6) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.6) lib/rails/engine.rb:479:in `call'
railties (3.2.6) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.6) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Rendered /var/lib/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (2.0ms)
I think that the problem is that I'm trying to access files using relative paths. My layout file looks like this:
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="viewport" content="width=device-width">
<title>:: Final ::</title>
<link rel="stylesheet" type="text/css" href="../../assets/stylesheets/style.css">
<link href="../../assets/stylesheets/desktop.css" rel="stylesheet" type="text/css" media="only screen and (min-width:769px) and (max-width:1000px)">
<script src="../../assets/javascripts/modernizr.js" type="text/javascript"></script>
</head>
<body>
<%= yield %>
</body>
</html>
Also, within the body of my final_page.html.erb file, I try to access images using relative paths as well...like so:
<img src="../../assets/images/mainImg.jpg" alt="img">
My friend wrote most of this html, and he has 0 experience working with rails. I decided to change the requests for assets like so:
From:
<link rel="stylesheet" type="text/css" href="../../assets/stylesheets/style.css">
To:
<%= stylesheet_link_tag "application.css" %>
From:
<script src="../../assets/javascripts/modernizr.js" type="text/javascript"></script>
To:
<%= javascript_include_tag "application.js" %>
From:
<img src="../../assets/images/mainImg.jpg" alt="img">
To:
<%= image_tag "mainImg.jpg" %>
This somewhat helps, as the images load, and very little of the styling comes through; however, it's way off from what it's supposed to look like. I'm thinking it's because my friend makes relative calls within the css files themselves:
body {
background-image: url(../images/bg.jpg);
background-repeat: repeat;
}
I've tried replacing these with url(<%= asset_path 'bg.jpg' %>) etc...
but it has no effect. I've tried so many things, and have read so many posts. I'm wondering if there's a way that Rails will allow me to use relative paths. I've tried:
config.assets.enabled = false
but that doesn't help ... please ... what am I doing wrong? I don't think my friend will want to stop using relative paths for his work, as it is how he does things. The site fires up well outside of Rails, but I need it to work with Rails for my webapp. Any advice would be greatly appreciated. Thank you for having the patience for reading all of this.
P.S. I'm using Ruby 1.9.3, and Rails 3.2.6
Try to use /assets/style.css not /assets/stylesheets/style.css and so on.
If there is such structure:
app
assets
stylesheets
javascripts
Then to get access to files in app/assets or in app/assets/any_folder you should use path /assets/file.
Updated
Here try:
body {
background-image: url(bg.jpg);
background-repeat: repeat;
}
Or:
body {
background-image: url(/assets/bg.jpg);
background-repeat: repeat;
}
Rails 3.1 introduced the new Asset Pipeline. I would recommend you read over this: http://guides.rubyonrails.org/asset_pipeline.html
In your app/views/layouts/application.html.erb file, make sure you have this:
<%= stylesheet_link_tag "application", :media => "all" %>
In your app/assets/stylesheets/application.css file, make sure you have this line:
*= require_tree .
(This will ensure that any css files that you have in the app/assets/stylesheets directory will be available to your application)
in your css file you can just do this to reference images in your app/assets/images directory:
background-image: url(bg.jpg);
In case you want to use local resources in your configuration initializers and you have this folder structure:
app
assets
stylesheets
javascripts
All you have to do is: (in this sample im using Spree base config/initializer)
Spree.config do |config|
config.admin_interface_logo = '/assets/logo/custom_admin.png'
config.logo = '/assets/logo/custom_store.jpg'
end
So use /assets/your_file_or_path and it will work :D

Resources