New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carrierwave is not compatible with Globalize3 #418

Closed
Gu1111 opened this Issue Aug 3, 2011 · 11 comments

Comments

Projects
None yet
9 participants
@Gu1111

Gu1111 commented Aug 3, 2011

When trying to use CarrierWave on a Globalize3 Column (ActiveRecords) the app crashes with an error:

undefined method `attribute_will_change!

The combination of Carrierwave and Globalize3 can be very useful if the admin wants to upload different images for different locales.

@trevorturk

This comment has been minimized.

Show comment
Hide comment
@trevorturk

trevorturk Aug 5, 2011

Contributor

Can you provide a small sample app or something? Is this an old Rails version? Maybe it doesn't support the "dirty tracking" features we assume to be present? CarrierWave is now Rails 3 only.

Contributor

trevorturk commented Aug 5, 2011

Can you provide a small sample app or something? Is this an old Rails version? Maybe it doesn't support the "dirty tracking" features we assume to be present? CarrierWave is now Rails 3 only.

@Gu1111

This comment has been minimized.

Show comment
Hide comment
@Gu1111

Gu1111 Aug 5, 2011

I am using rails 3.0.9.

All you really need to do to reproduce the problem is install Globalize3 and Carrierwave then call "translate" on one of your columns in your model and run the Globalize migration (This basically create a new table called model_name_translations with the column you specified and a row for each locale)

If you use one of those text columns with Carrierwave you get "undefined method `attribute_will_change!" error

Globalize3 hides the fact that your column is in a different table by allowing you to access it using model_name.col while Globalize3 fetch the current value for your current locale and I guess this is where CarrierWave doesn't get along with Globalize3.

Gu1111 commented Aug 5, 2011

I am using rails 3.0.9.

All you really need to do to reproduce the problem is install Globalize3 and Carrierwave then call "translate" on one of your columns in your model and run the Globalize migration (This basically create a new table called model_name_translations with the column you specified and a row for each locale)

If you use one of those text columns with Carrierwave you get "undefined method `attribute_will_change!" error

Globalize3 hides the fact that your column is in a different table by allowing you to access it using model_name.col while Globalize3 fetch the current value for your current locale and I guess this is where CarrierWave doesn't get along with Globalize3.

@trevorturk

This comment has been minimized.

Show comment
Hide comment
@trevorturk

trevorturk Aug 5, 2011

Contributor

Thanks for the info. I'm sorry to say, but I haven't heard of this issue before, so you may be the only person experiencing it. That means you may have to take it upon yourself to try and fix it, if you have the time and ability. I'll leave this issue open for now, but if you (or someone else) doesn't find a resolution, we'll document the problem in the "known issues" wiki page and leave it at that. I'm sorry for the problem. Good luck!

Contributor

trevorturk commented Aug 5, 2011

Thanks for the info. I'm sorry to say, but I haven't heard of this issue before, so you may be the only person experiencing it. That means you may have to take it upon yourself to try and fix it, if you have the time and ability. I'll leave this issue open for now, but if you (or someone else) doesn't find a resolution, we'll document the problem in the "known issues" wiki page and leave it at that. I'm sorry for the problem. Good luck!

@trevorturk

This comment has been minimized.

Show comment
Hide comment
@trevorturk

trevorturk Aug 9, 2011

Contributor

I'm going to close this for now. Feel free to add an entry to the "known issues" wiki page and/or call for help on the Google Group.

Contributor

trevorturk commented Aug 9, 2011

I'm going to close this for now. Feel free to add an entry to the "known issues" wiki page and/or call for help on the Google Group.

@trevorturk trevorturk closed this Aug 9, 2011

@osegrums

This comment has been minimized.

Show comment
Hide comment
@osegrums

osegrums Oct 7, 2011

Here is an example how to make translated attachments (If you have different images in different languages):

class Page < ActiveRecord::Base
  translates :title, :banner

  accepts_nested_attributes_for :translations

  Translation.mount_uploader :banner, BannerUploader
end

work fine for me

osegrums commented Oct 7, 2011

Here is an example how to make translated attachments (If you have different images in different languages):

class Page < ActiveRecord::Base
  translates :title, :banner

  accepts_nested_attributes_for :translations

  Translation.mount_uploader :banner, BannerUploader
end

work fine for me

@jenzer

This comment has been minimized.

Show comment
Hide comment
@jenzer

jenzer Nov 8, 2011

Thanks osegrums for you snippet, but it still does not work for me. Is there any other workaround?

jenzer commented Nov 8, 2011

Thanks osegrums for you snippet, but it still does not work for me. Is there any other workaround?

@effkay

This comment has been minimized.

Show comment
Hide comment
@effkay

effkay Jan 18, 2012

@osegrums calling mount_uploader on Translation got rid of the _will_change error, but now I'm getting undefined method 'name' for nil:NilClass. For some reason the attribute with the uploader (@page.banner in your case) is not of class BannerUploader but ActionDispatch::Http::UploadedFile. Did you run into anything similar?

effkay commented Jan 18, 2012

@osegrums calling mount_uploader on Translation got rid of the _will_change error, but now I'm getting undefined method 'name' for nil:NilClass. For some reason the attribute with the uploader (@page.banner in your case) is not of class BannerUploader but ActionDispatch::Http::UploadedFile. Did you run into anything similar?

@hugobast

This comment has been minimized.

Show comment
Hide comment
@hugobast

hugobast Mar 4, 2013

@effkay, @jenzer this might not be relevant to you now after a year but for those that stumble upon this page while researching what translations method would work with carrierware I'll elaborate what you need to do in order to get pass the 'name' for nil:NilClass issue. The Translation model owns the uploads and you can access it with model.translation. Now what you need to do is assign the file through the translation model.translation.banner = params[:file] and then model.save will work. There are a couple caveats like banner_url will not work directly on the model but banner.url will and minor stuff like that.

hugobast commented Mar 4, 2013

@effkay, @jenzer this might not be relevant to you now after a year but for those that stumble upon this page while researching what translations method would work with carrierware I'll elaborate what you need to do in order to get pass the 'name' for nil:NilClass issue. The Translation model owns the uploads and you can access it with model.translation. Now what you need to do is assign the file through the translation model.translation.banner = params[:file] and then model.save will work. There are a couple caveats like banner_url will not work directly on the model but banner.url will and minor stuff like that.

@moreinput

This comment has been minimized.

Show comment
Hide comment
@moreinput

moreinput Mar 25, 2013

@hugobast, @osegrums - thanks a lot for the suggestions on solving this kind of issue - unfortunately it seems like this is not enough in my code.
Surprisingly it doesn't matter how I try to save the uploaded file in the controller: I don't get any errors, but the 'file' (or in the example above the 'banner') is always blank.

I have 'Posts', that have many 'Attachments' (1 to n), and these have several localizations as attachment 'files'. It seems to make no difference whether I try to save the attachments putting Posts.attachment.new(:file => params['file']) Post.saveor att=Posts.attachment.new att.translation.file=params['file'].

The params['file'] contains the full ActionDispatch Object, so I'm assuming that it's not being recognized that I'm trying to upload a file.
Does anyone have an idea what I'm missing?
Sorry, if this is a noob issue and not related to issues between globalize and carrierwave...

moreinput commented Mar 25, 2013

@hugobast, @osegrums - thanks a lot for the suggestions on solving this kind of issue - unfortunately it seems like this is not enough in my code.
Surprisingly it doesn't matter how I try to save the uploaded file in the controller: I don't get any errors, but the 'file' (or in the example above the 'banner') is always blank.

I have 'Posts', that have many 'Attachments' (1 to n), and these have several localizations as attachment 'files'. It seems to make no difference whether I try to save the attachments putting Posts.attachment.new(:file => params['file']) Post.saveor att=Posts.attachment.new att.translation.file=params['file'].

The params['file'] contains the full ActionDispatch Object, so I'm assuming that it's not being recognized that I'm trying to upload a file.
Does anyone have an idea what I'm missing?
Sorry, if this is a noob issue and not related to issues between globalize and carrierwave...

@venturanima

This comment has been minimized.

Show comment
Hide comment
@venturanima

venturanima Sep 20, 2013

I was having the exact same problem that @effkay was; fixed it by making sure that "translates :banner" was before mount_uploader.

venturanima commented Sep 20, 2013

I was having the exact same problem that @effkay was; fixed it by making sure that "translates :banner" was before mount_uploader.

@jamesalbuquerque

This comment has been minimized.

Show comment
Hide comment
@jamesalbuquerque

jamesalbuquerque May 7, 2017

Have the same issue.

class Cover < ActiveRecord::Base

	translates :cover, :author, :description

	mount_uploader :cover, CoverUploader
	attr_accessor :cover, :cover_cache

<%= f.fields_for :cover do |builder| %>
	<div class="cover clearfix">
		<div class="overlay">
			<%= image_tag @post.cover && @post.cover.cover unless @post.cover && @post.cover.cover.blank? %>
			<%= builder.file_field :cover, id: 'uploadify' %>
def new
    @post = current_user.posts.build
    @post.build_cover
end

def create
    @post = current_user.posts.build(post_params)
end

Went saving, everything looks ok:
"cover_attributes"=>{"cover"=>#<ActionDispatch::Http::UploadedFile:0x007f8b53b15a90 @tempfile=#<Tempfile:/var/folders/ht/80rd8_d53_vgrqzbwnr8lk2w0000gn/T/RackMultipart20170507-28076-1j9p1ma.jpg>, @original_filename="20PRE-master768.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"post[cover_attributes][cover]\"; filename=\"20PRE-master768.jpg\"\r\nContent-Type: image/jpeg\r\n">

If I try to the command Cover.last it always has cover: nil

jamesalbuquerque commented May 7, 2017

Have the same issue.

class Cover < ActiveRecord::Base

	translates :cover, :author, :description

	mount_uploader :cover, CoverUploader
	attr_accessor :cover, :cover_cache

<%= f.fields_for :cover do |builder| %>
	<div class="cover clearfix">
		<div class="overlay">
			<%= image_tag @post.cover && @post.cover.cover unless @post.cover && @post.cover.cover.blank? %>
			<%= builder.file_field :cover, id: 'uploadify' %>
def new
    @post = current_user.posts.build
    @post.build_cover
end

def create
    @post = current_user.posts.build(post_params)
end

Went saving, everything looks ok:
"cover_attributes"=>{"cover"=>#<ActionDispatch::Http::UploadedFile:0x007f8b53b15a90 @tempfile=#<Tempfile:/var/folders/ht/80rd8_d53_vgrqzbwnr8lk2w0000gn/T/RackMultipart20170507-28076-1j9p1ma.jpg>, @original_filename="20PRE-master768.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"post[cover_attributes][cover]\"; filename=\"20PRE-master768.jpg\"\r\nContent-Type: image/jpeg\r\n">

If I try to the command Cover.last it always has cover: nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment