lllllll
lllllll

Reputation: 4835

Accessing Rails assets ignoring the scoped locale in the URL

I set the background of my homepage via JS-jQuery:

$(function(){
  $('.nonsignedin-home').closest('html').css({
    'background-image':"url('assets/my_background.jpg')",
    'background-repeat': "no-repeat",
    'background-size':'cover'
  });
});

Everything was working well until I introduced locales in my app. Since I decided to scope my URL's with the selected locale:

MyApp::Application.routes.draw do
  scope ":locale" do
    #My routes here
  end
end

Now totally understandably there's a routing error:

ActionController::RoutingError (No route matches [GET] "/es/assets/my_background.jpg"):

since the URL is locale-scoped. And my background image is located in assets/images/my_background.jpg.

The question is, how can I bypass this es scope in my URL when accessing assets? I have no interest in having different background for each locale.

Upvotes: 0

Views: 64

Answers (1)

A Fader Darkly
A Fader Darkly

Reputation: 3636

$(function(){
  $('.nonsignedin-home').closest('html').css({
    'background-image':"url('/assets/my_background.jpg')",
    'background-repeat': "no-repeat",
    'background-size':'cover'
  });
});

Does that help? Note the extra '/' in front of your assets path.

Upvotes: 3

Related Questions