Weird asset url without 'http' in Rails 3.1 - ruby-on-rails

I'm using Rails 3.1.1, Ruby 1.9.3, asset_host='assets.foo.com'
This
<%= stylesheet_link_tag 'home' %>
<%= javascript_include_tag 'home' %>
produces
<link href="http://assets.foo.com/assets/home-f803345a3514568545f88946a69d6bab.css" media="screen" rel="stylesheet" type="text/css" />
<script src="//assets.foo.com/assets/home-da846573d17e8a062b5a8d6c122abc97.js" type="text/javascript"></script>
I can't figure out why the script's src is malformed.
I see similar URLs without the protocol schema in CSS file, as the result of the image-url() Sass helper.
Where should I look to resolve this?

It's not malformed. Most modern browsers these days will automatically put in the protocol you're using when it sees the //. It's called relative protocol resolution.
See this answer as well as RFC 3986 Section 5.2

Related

Devise Views Not Getting Styled in Rails

I have been working on an application for the Rhode Island State Police. I decided to use the devise gem to handle user auth. After running rails generate devise user. I went to the /sign_up page, and found that it was all there, but just as html. For an example of my problem check out my app
http://systemsgroup2.herokuapp.com/
http://systemsgroup2.herokuapp.com/users/sign_in
Thanks for the help.
Your stylesheets are referenced relative to the current path.
In your layouts (or where ever you include your stylesheets) change the paths from
<link rel="stylesheet" href="assets/skel.css" />
<link rel="stylesheet" href="assets/style.css" />
<link rel="stylesheet" href="assets/style-wide.css" />
to
<link rel="stylesheet" href="/assets/skel.css" />
<link rel="stylesheet" href="/assets/style.css" />
<link rel="stylesheet" href="/assets/style-wide.css" />
Your stylesheets are not loading for the /user directory because instead of looking for assets/stylesheets it is looking for assets/users/stylesheets. To fix this you can use Rails stylesheet helper instead of manually linking to the stylesheets:
<%= stylesheet_link_tag "application" %>

JQuery and JQuery ujs tags in rails

I need to get access to Jquery and Jquery-ujs through the liquid template language. To do this i use javascript_include_tag("jquery") to get the file to work in production.
The problem is that javascript_include_tag is giving me the wrong links:
<script src="/javascripts/jquery.js"></script>
<script src="/javascripts/jquery_ujs.js"></script>
What i need is something similar to this in development:
<script src="/assets/jquery.js"></script>
<script src="/assets/jquery_ujs.js"></script>
I believe the problem is related to how i call the javascript_include_tag.

Rails Tutorial 3, stylesheet_link_tag generating incorrect link

I've set up application.html.erb to link to a stylesheet using the following code
<%= stylesheet_link_tag 'stylesheets/style', :media => 'screen' %>
However when I load the localhost in the browser window it prints this code
<link href="/assets/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />
when I view the file directly I'm shown this error
Routing Error
No route matches [GET] "/assets/stylesheets/style.css"
I've read on some other questions that rails by default looks in public/stylesheets so I'm not sure why it's looking in assets?
I also tried to move the css file to the assets directory just to see if it would work however, it still doesn't work and gives the same routing error.
Been stuck on this for a couple of days and it's really doing my head in so appreciate any help you can give me.
Thanks in advance
Rails 3 comes with a new assets management which is actually one of the biggest pluses.
A guide on how it works is here
So if you have the application.css file in your assets/stylesheets you can simply drop the style.css in your assets/stylesheets directory renaming it in style.css.scss
In your view just leave:
<%= stylesheet_link_tag "application", media: 'screen' %>
Through sprockets the Rails app will load it.

Can't get CSS to load

I can't seem to get a css file to apply its styling to a form. It is quite frustrating now because as far as I know it should work!
In my head I have
<link href="/stylesheets/formtastic.css?1290524609" media="screen" rel="stylesheet" type="text/css" />
and in the body I have:
<form action="/agents" class="formtastic agent" id="new_agent" method="post">
The formtastic.css file should apply styling to the form. It's contents are viewable here:
formtastic.css
Any suggestions or fixes?
The problem was that the following code was not inserted in the form:
<% f.inputs do %>
This creates the html and now the css works.
i.e. the html missing was
dont you need to turn that number into a querysting var?
<link href="/stylesheets/formtastic.css?math=1290524609" media="screen" rel="stylesheet" type="text/css" />
Are you using this with Rails? If so, you could simply put this in your header:
<%= formtastic_stylesheet_link_tag %>
Also, have you run both bundle install and rails generate formtastic:install (for Rails 3, use ./script/generate formtastic for Rails 2)?
Are you sure the path is correct? if you check source with firebug check the link tag and see if its contents are a 404 error. It may be an issue with your root-relative path.
This is only a guess as I can't see how your site is structured.
Are you sure you have to begin with a forward slash ? (/)
Cause it's mean it's at the root of your domain.
Tried <link href="stylesheets/formtastic.css?1290524609" media="screen" rel="stylesheet" type="text/css" /> ?

Problem with stylesheet_link_tag

I have add stylesheet link tag to my application. I'm sure its worked. because in another place is working. but if I run at my computer it did not working. I mean my application cant load css
when I seen at view source the result is :
<script src="http://localhost:3000//javascripts/application.js?1258048544" type="text/javascript"></script>
<link href="http://localhost:3000//stylesheets/jquery.autocomplete.css?1258048544" media="screen" rel="stylesheet" type="text/css" />
I'm sure it shouldnt appear double slash // after domain or localhost:3000. weird why in other computer it was worked.
Have you any suggestion for this case? how to change double slash with single?
btw I use ubuntu.
The Rails helpers should not render an absolute url, it should simply be a relative path.
<link href="/stylesheets/jquery.autocomplete.css?1250281505" media="screen" rel="stylesheet" type="text/css" />
Make sure you are using the stylesheet_link_tag properly - do not use a leading slash or the trailing .css when specifying the stylesheet name. Same for javascript_include_tag.
<%= stylesheet_link_tag "jquery.autocomplete" %>
Maybe this helps:
Relative paths from root-stucture: "/your/path/to/file.ext"
Relative paths from the current file "your/path/to/file.ext"
Try these helper methods:
<%= stylesheet_link_merged 'jquery.autocomplete.css' %>
<%= javascript_include_tag 'application.js'%>
*Works with http://synthesis.sbecker.net/pages/asset_packager
I had a similar problem and just discovered the issue–it may or may not work for you.
My app uses the Facebooker gem to integrate with Facebook Connect. In my facebooker.yml file, if I had a trailing slash in my callback_url setting, I would get the same behavior as you described. Removing the trailing slash fixed the issue.

Resources