Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7981175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:17:38+00:00 2026-06-04T10:17:38+00:00

Paperclip initializes styles before form parameters are processed, thereby ignoring my attempt to specify

  • 0

Paperclip initializes styles before form parameters are processed, thereby ignoring my attempt to specify a custom resize.

Model:

    attr_accessor :new_width, :new_height        

    has_attached_file :attachment,
      styles: lambda { |attachment| attachment.instance.set_styles }
      ...

    def set_styles
      # Default thumb:
      styles = { thumb: '100x100>' }

      # Resize original if new sizes have been specified
      if new_width and new_height
        styles[:original] = "#{new_width}x#{new_height}>"
      end

      styles
    end

I can see through the log files that styles are defined and the convert command triggers before new_width and new_height are assigned the values passed by the controller.

Rails server log file:

    {:thumb=>"100x100>"} # logger.info in the model
    ...
    # Command :: convert ... etc
    # [paperclip] Saving attachments.
    ...
    {:thumb=>"100x100>", :original=>"300x300>"}  # logger.info in the model

By the time the custom dimensions are assigned to the instance, the ImageMagick command has already been triggered by Paperclip.

How can I pass custom dimensions to Paperclip to define the styles before the image is processed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:17:39+00:00Added an answer on June 4, 2026 at 10:17 am

    Have you tried using a callback in your model to calculate the width and height before saving the model?

    before_save :set_styles
    

    From the paperclip documentation on attachments, the paperclip attachment saves when the model saves and process the file upon assignment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GalleryPhoto model with a paperclip attachment that gets processed into a
The Paperclip plugin for Rails has a resize option that keeps the image in
I've a model which use paperclip, in dev env I want to store files
It looks like Paperclip doesn't honor the ActiveRecord dirty model. How do I detect
I have installed the Paperclip plugin to attempt to upload an avatar for my
I've been using paperclip to upload and auto-resize photos in my Rails app, and
(I am new to paperclip) I have this model hierarchy: base model: class QuestDescription
I'm using Paperclip with a Ruby on Rails to attach assets to a model,
I use Paperclip like this: class Asset < ActiveRecord::Base has_attached_file :asset, :styles => {
Formerly: Running a model method on a paperclip attachment after create or update (paperclip

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.