kirtithorat / carrierwave-crop

Carrierwave extension to crop uploaded images using Jcrop plugin with preview.
MIT License
94 stars 58 forks source link

Colons in html id attributes #1

Closed Lorjuo closed 10 years ago

Lorjuo commented 10 years ago

Hi and thanks for this great gem. I have found a little problem that appears when I am using Namespaced Models. This causes the previewbox and cropbox helper to create html tags with colons "::" inside the id attribute. For example if my model is Asset::Image and my attachement is file, the helpers will create tags with the ids "asset::image_file_previewbox" and "asset::image_file_cropbox". Although this is valid according to w3c, this causes some problems when you try to access these attributes by jquery, because you have to escape all colons with a double backslash linke this:

$('#asset\\:\\:image_file_cropbox').Jcrop

It also differs from the rails convention, that only uses underscores as delimiter inside html ids.

Maybe it would be enough to replace all double colons "::" inside "model_name" in helpers.rb with one underscore

kirtithorat commented 10 years ago

@Lorjuo Thanks for the update. :)

I think I would consider using pure model name sans the namespace name, so for model Asset::Image you would get an id image_file_cropbox. This way it will be in sync across all scenarios, with or without namespace. I'll provide a minor fix for the same.

One quick question, you had to manually change the generated the js for your Namespaced Model, from

$('#image_file_cropbox').Jcrop

to

$('#asset\\:\\:image_file_cropbox').Jcrop

Let me know.

Lorjuo commented 10 years ago

I think the solution without the namespace would work for me. And yes, I manually changed the generated js link above, but now I'll probably no longer have to do this. Thanks

kirtithorat commented 10 years ago

@Lorjuo I have fixed the issue and it would be part of next release. For now you can source the gem directly from github with gem 'carrierwave-crop', github: 'kirtithorat/carrierwave-crop' in your Gemfile.