Skip to content
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

Fix crash with protected_attributes and rails 4.2 #14

Merged
merged 1 commit into from
Jul 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 14 additions & 20 deletions lib/technoweenie/attachment_fu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,12 @@ def create_or_update_thumbnail(temp_file, file_name_suffix, *size)
thumbnailable? || raise(ThumbnailError.new("Can't create a thumbnail if the content type is not an image or there is no parent_id column"))
find_or_initialize_thumbnail(file_name_suffix).tap do |thumb|
thumb.temp_paths.unshift temp_file
assign_attributes_args = []
assign_attributes_args << {
:content_type => content_type,
:filename => thumbnail_name_for(file_name_suffix),
:thumbnail_resize_options => size
attributes = {
content_type: content_type,
filename: thumbnail_name_for(file_name_suffix),
thumbnail_resize_options: size
}
if defined?(Rails) && Rails::VERSION::MAJOR == 3
# assign_attributes API in Rails 2.3 doesn't take a second argument
assign_attributes_args << { :without_protection => true }
end
thumb.send(:assign_attributes, *assign_attributes_args)
attributes.each{ |a, v| thumb.send "#{a}=", v }
callback_with_args :before_thumbnail_saved, thumb
thumb.save!
end
Expand Down Expand Up @@ -436,8 +431,8 @@ def with_image(&block)
# Write out the temporary data if it is not present
if temp_data.nil?
self.temp_data = current_data
end
end

self.class.with_image(temp_path, &block)
end

Expand Down Expand Up @@ -480,15 +475,14 @@ def attachment_attributes_valid?

# Initializes a new thumbnail with the given suffix.
def find_or_initialize_thumbnail(file_name_suffix)
if defined?(Rails) && Rails::VERSION::MAJOR >= 4
respond_to?(:parent_id) ?
thumbnail_class.find_or_initialize_by(:thumbnail => file_name_suffix.to_s, :parent_id => id) :
thumbnail_class.find_or_initialize_by(:thumbnail => file_name_suffix.to_s)
else
respond_to?(:parent_id) ?
thumbnail_class.find_or_initialize_by_thumbnail_and_parent_id(file_name_suffix.to_s, id) :
thumbnail_class.find_or_initialize_by_thumbnail(file_name_suffix.to_s)
attrs = {thumbnail: file_name_suffix.to_s}
attrs[:parent_id] = id if respond_to? :parent_id
thumb = thumbnail_class.where(attrs).first
unless thumb
thumb = thumbnail_class.new
attrs.each{ |a, v| thumb[a] = v }
end
thumb
end

# Stub for a #process_attachment method in a processor
Expand Down