Where to put plugin images in Rails application?

Originally posted here: http://stackoverflow.com/questions/15986969/where-to-put-plugin-images-in-rails-application

We use handful of plugins in our Rails application(Rails 3.2.1). As we already know that we should keep all app images app/assets/images folder and css in app/assets/stylesheets. This is what we follow.

However some plugins use images and keep them in parallel to CSS file.(images and CSS in same folder/level)

So my question is: (We use Asset Pipeline)

  1. Is it a good practice to keep images of plugin in parallel to CSS file? (I am hoping it’s good thing)
  2. If not, then developer has to change the image paths in entire css file (if putting plugin images inapp/assets/images), Which I think is not helpful for future in case you plan to upgrade those plugins. Thanks.

Originally posted here: http://stackoverflow.com/questions/15986969/where-to-put-plugin-images-in-rails-application

We use handful of plugins in our Rails application(Rails 3.2.1). As we already know that we should keep all app images app/assets/images folder and css in app/assets/stylesheets. This is what we follow.

However some plugins use images and keep them in parallel to CSS file.(images and CSS in same folder/level)

So my question is: (We use Asset Pipeline)

  • Is it a good practice to keep images of plugin in parallel to CSS file? (I am hoping it's good thing)   • If not, then developer has to change the image paths in entire css file (if putting plugin images inapp/assets/images), Which I think is not helpful for future in case you plan to upgrade those plugins. Thanks.

You might want to put these in the app/vendor/plugin_name/assets folder tree, so you can keep them separate from your application's own code. If these stylesheets are written with "awareness" of a folder hierarchy, like maybe with ../images/icon.png style references to images, then you may have trouble with the asset pipeline. I just ran into that in a project here, and had to give up and let the "magic" work by removing all prefixes. Once I did that, and just referenced url(icon.png) in my CSS, everything just worked. (icon.png was in the app/assets/images folder, the stylesheet referencing it was in the app/assets/stylesheets folder.)

Walter

Thanks Walter.

So in your opinion it is always good to write css without folder prefixes. Am I getting you right here?

-deepak

Thanks Walter.

So in your opinion it is always good to write css without folder prefixes. Am I getting you right here?

I'd never done that until this week, but then I am extremely late to the asset pipeline party. I have always written mine with the ../images prefix, because that was what you needed in the public folder. But when I tried doing that, and discovered it didn't work, I just bailed and put the reference in without the prefix and discovered that it worked fine that way, without any need for the asset_path helper and css.erb or anything else.

Walter

Hey guys, I'm having trouble testing a helper that uses content_for. I am using test::unit and hitting a road block. below is my code and below that is the error I am hitting. Any help would be much appreciated.

Matt

-- my helper def --   def page_title(title)     content_for(:title) { "#{title} | my title" }   end

-- my test --   test "displays page title" do     assert_equal "my test | my title", page_title("my test")   end

NoMethodError: undefined method `append' for nil:NilClass