Hi--

On May 9, 2009, at 6:53 PM, Bharat Ruparel wrote:

>
> This has to do more with Rails than jQuery so I am posting it here.  I
> am using jQuery UI widgets in my application.  One of the CSS file is
> called ui.theme.css which has references to background-image as shown
> below:
>
> .ui-widget-content .ui-icon {background-image:
> url(images/ui-icons_222222_256x240.png)/*{iconsContent}*/; }
>
> Following Rails conventions, I put the stylesheets in public/ 
> stylesheets
> and javascripts in public/javascripts directories.
>
> Trouble is: this creates problems in terms of background images not
> loading correctly, I have to change the aforementioned line to:
>
> .ui-widget-content .ui-icon {background-image:
> url('/images/ui-icons_222222_256x240.png')/*{iconsContent}*/; }
>
> In other words, put a forward slash "/" in front of the images and put
> the whole uri string in quotes for Rails to load it correctly.  This
> seems like a lot of work for no good reason.  Any advice on how to get
> around it without having to modify the CSS files?

I don't think it's a Rails thing. I think it's the way URLs are  
resolved into physical pathnames by Web servers. A document-relative  
URL is always (AFAIK) going to load the specified resource relative to  
the directory in which the current document exists by default. Because  
Rails "fakes" a rather deeper directory structure using routing, the  
only time a server will try to load a resource like images/ui- 
icons_22222_256x240.png from public/images is if your are looking at a  
document called '/'.

There are several ways to approach this. I humbly call them the  
expensive way, the cheap-but-brittle way, and the Apache way.

Expensive way: Put code in your routes.rb to snag the request for your  
ui-icons and map them to the correct directory. Why not? Because they  
all of a sudden become dynamic resources and expensive to serve.

Cheap-but-brittle way: Make the change to the CSS and get on with it.  
That's what I do and I believe it's pretty common practice. When you  
upgrade versions, it's brittle, shatters into a million pieces, but  
it's easy to spot.

Apache way: Write some keen rewrite rule that recognizes your jQ-UI  
resource and maps it to the correct location no matter where your  
document exists.

Obviously there are variants for nginx and there might even be some  
keen Metal solution I haven't thought of. But really, overthinking  
this one won't get you to done much quicker.

Good luck.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to