favicon.ico being rendered as part of query parameter; probable route issue - ruby-on-rails

In localhost / WEBrick configuration (Rails 3.1, ruby 1.9.2, one of my routes takes the favicon.ico file as a request parameter. It seems to be only on this one route and am not sure sure why it is doing this:
In my routes:
routes.rb
scope '/arc' do
match '/item/:id' => 'items#show', :as => :item_show # id can be either integer or text
end
In html:
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
Started GET "/arc/item/test-306-some-item" for 127.0.0.1 at 2012-10-18 12:18:18 -0700
...
why is it doing this??? only on the above route?
Started GET "/arc/item/favicon.ico" for 127.0.0.1 at 2012-10-18 12:18:22 -0700
Creating scope :page. Overwriting existing method Item.page.
Processing by ItemsController#show as
Parameters: {"id"=>"favicon"}
Any ideas on why it would be doing this?

Use absolute URI /favicon.ico and then it will work as expected.

You need to give the full path of the favicon
Like
<link rel="shortcut icon" href="/assets/favicon.ico" type="image/x-icon" />
In order to work in all environment like development and production you can use Rails tag for this
<%= favicon_link_tag "favicon.ico" %>

Try:
<link rel="icon" type="image/png" href="<%= image_path("favicon.png") %>" />

Related

Jasmine specs are not loading in any of the correct assets using jasmine-rails gem

I am using the jasmine-rails gem to try and get our jasmine test suite working.
In my routes right at the top I have defined the following;
mount JasmineRails::Engine => '/specs' if defined?(JasmineRails)
And that seems to work, I can browse to /specs and the title of the page is Jasmine Specs.
The issue is that none of the assets that Jasmine needs are being loaded, including the specs. In my console I am seeing;
GET http://acme.lvh.me:8081/specs/assets/jasmine-specs.css 404 (Not Found) specs:21
GET http://acme.lvh.me:8081/specs/assets/jasmine.js 404 (Not Found) specs:22
GET http://acme.lvh.me:8081/specs/assets/jasmine.css 404 (Not Found) specs:20
GET http://acme.lvh.me:8081/specs/assets/jasmine-html.js 404 (Not Found) specs:23
GET http://acme.lvh.me:8081/specs/assets/boot.js 404 (Not Found) specs:25
GET http://acme.lvh.me:8081/specs/assets/json2.js 404 (Not Found) specs:24
GET http://acme.lvh.me:8081/specs/assets/jasmine-specs.js 404 (Not Found)
I am not quite sure why /specs/ is in that path?
My jasmine.yml is;
spec_files:
- "**/*[Ss]pec.{js,coffee}"
Any help would be greatly appreciated.
I was able to fix this by created a custom template
app/views/layouts/jasmine_rails/spec_runner.html.erb
And manually looping and creating the CSS/JS includes;
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
<title>Jasmine Specs</title>
<% jasmine_css_files.each do |css_file| %>
<link href="/assets/<%= css_file %>" media="screen" rel="stylesheet" />
<% end %>
<% jasmine_js_files.each do |js_file| %>
<script src="/assets/<%= js_file %>"></script>
<% end %>
</head>
<body>
<div id="jasmine_content"></div>
<%= yield %>
</body>
</html>

ActionView::Template::Error (defaults.js isn't precompiled)

Recently, I've been working on migrating my Ruby on Rails site, built on passenger, to a different server, and in the process upgrade rails from 2.3.2 to 3.2. I've installed all necessary gems, and I thought configured everything correctly, but when I go to my site, I get a "We're sorry, but something went wrong" message
I checked the production.log and this is the error message I got:
Connecting to database specified by database.yml
Started GET "/login/login" for ip_address at 2013-05-31 20:12:28 -0400
Processing by LoginController#login as HTML
Rendered login/login.html.erb within layouts/homepage (6.9ms)
Completed 500 Internal Server Error in 43ms
ActionView::Template::Error (defaults.js isn't precompiled):
6:<title>test test test</title>
7: <link rel="icon" type="image/png" href="/images/favicon.ico">
8: <link rel="SHORTCUT ICON" href="/images/favicon.ico"/>
9: <%= javascript_include_tag :defaults %>
10: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
11: <script type="text/javascript" >src="http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js"></script>
12: <script type="text/javascript" src="/javascripts/jquery-ui->1.8.20.custom.min.js"></script> <%= stylesheet_link_tag 'home_styles', :media => >'Screen' %>
app/views/layouts/homepage.html.erb:9:in
_app_views_layouts_homepage_html_erb__3199970246383683518_43112000'
I'm still pretty new to Rails, so I'm currently at a bit of a loss what to do. Any help would be appreciated!
<%= javascript_include_tag :defaults %>
This tag is from Rails versions pre 3.1. Are you sure this is what you want to do?
In newer applications, this line is typically including the application JavaScript file instead:
<%= javascript_include_tag "application" %>
This is made possible due to the Asset Pipeline which you can learn about by reading The Asset Pipeline Guide.

How to have absolute path for stylesheets in mailer with the asset pipeline?

The view helpers in my Mailer template give me relative URLs to the stylesheet and images. Of course, this won't work if I'm viewing the email in Gmail, for example.
In apps/views/layouts/mailer.html.erb
<%= stylesheet_link_tag "application" %>
...
<%= link_to(image_tag("logo.png"), "http://mysite.com") %>
Renders as:
<link href="/assets/application-c90478153616a4165babd8cc6f4a28de.css" media="screen" rel="stylesheet" type="text/css" />
...
<img alt="Logo" src="/assets/logo-d3adbf8d0a7f7b6473e2130838635fed.png" />
How do I get Rails to give me absolute links instead? I'm on Rails 3.1, the asset pipeline is in effect.
`config.action_controller.asset_host handles the host prefix in views generated from an ActionController.
For anything generated in an email you're looking for the ActionMailer configuration options, more specifically:
ActionMailer::Base.asset_host will handle your image_tags and
ActionMailer::Base.default_url_options[:host] will look after your link_to tags.
eg:
ActionMailer::Base.asset_host = "http://blah.com"
ActionMailer::Base.default_url_options[:host] = "blah.com"
Note that you don't need to specify the http prefix for the default url host, you will for the asset host.
I have specified these inside my environment.rb after the application initializer. I would recommend setting an application configuration variable for each environments domain.
For rails 3.2 and ActionMailer use:
config.action_mailer.asset_host = "http://www.example.com"
This might be a bit of a hack, but if you specify an asset host, all helpers will take it into account when rendering links. So if you set
config.action_controller.asset_host = "http://mysite.com"
in your config, stylesheet_link_tag will include the host name.
In this thread rocketscientist and Joe asked about other ideas:
http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/stylesheet_link_tag
You can generate full css as follows (if you do not care about asset hosting). However answer by David Radcliffe should work.
stylesheet_link_tag "http://www.railsapplication.com/style.css" # =>
<link href="http://www.railsapplication.com/style.css" media="screen" rel="stylesheet" type="text/css" />

Hpricot search all the tags under one specific namespace

For example I have the following code:
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><io:content part="title" /></title>
<link rel="icon" href="/document/7e9f29e2-cdee-4f85-ba25-132fa867aa90/latest" type="image/x-icon" />
<n1:content description="Standard CSS" uuid="d069071c-3534-4945-9fb6-2d7be35a165e" />
<n1:term>Content Development</n1:term>
</head>
This XHTML snippet is not strictly legal because there is no namespace declared before so I cannot use Nokogiri which has better namespace support.
I want to do a single search that can find both the node <n1:content> and <n1:term> and all the tags under 'n1' namespace.
How to achieve that? Thanks!
It looks like Hpricot does not handle namespaces that fully.
You can select if you know the element regardless of prefix:
doc.search("title")
=> #<Hpricot::Elements[{elem <title> {emptyelem <io:content part="title">} </title>}]>
... but this is not what you asked.
Here's my hack workaround: find all namespace elements using regex first, then search for those using Hpricot:
elems = doc.to_s.scan(/<\s*(n1:\w+)/).uniq.join("|")
=> "n1:content|n1:term"
doc.search(elems)
=> #<Hpricot::Elements[{emptyelem <n1:content description="Standard CSS" uuid="d069071c-3534-4945-9fb6-2d7be35a165e">}, {elem <n1:term> "Content Development" </n1:term>}]>

Rails ActionController::UnknownAction for favicon

I have following line in my app/views/layouts/application.html.erb
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
This somehow causes following error message int he logs and the favicon is not loaded. This happens only for certain paths not for the whole application.
ActionController::UnknownAction (No action responded to images. Actions:
How to get rid of it ?
Use the favicon_link_tag helper instead:
<%= favicon_link_tag "/favicon.ico" %>
Just make sure your favicon.ico file is in the public folder... and do not forget the forward slash.
Believe me.. try prefixing images with a slash and this should work
<link rel="shortcut icon" href="/images/favicon.ico" type="image/x-icon" />

Resources