Passing a parameter to the uploader / accessing a model's attribute from within the uploader / letting the user pick the thumbnail size

I would like to crop an image to the size the user has selected from a list (e.g. 100x100px, 200x200px,...) How would I pass that attribute to the uploader or get the model's attribute from within the uploader?

Accessing the model's attribute from within the uploader as following does not work:

version :thumb do thumbnail_size = model.thumbnail_size ... ... end

I get following error:

undefined local variable or method `model' for #

Thank you! Florian

-------------Problems Reply------------

In order to be able to access the model's attribute I had to add a manipulation helper.

class MyUploader < CarrierWave::Uploader::Base

version :thumb do
process :custom_thumbnail
process :convert => 'jpg'

def custom_thumbnail
width = model.get_image_width
height = model.get_image_height

manipulate! do |img|
img.convert "#{width}x#{height}"

Category:ruby on rails 3 Views:10 Time:2011-10-10

Related post

  • What's the point of having foreign keys if Rails can access other model's attributes through associations anyways? 2012-01-30

    I'm a Rails beginner (and loving it so far). I'm not sure if this is a stupid question. As far as I know, a foreign key, for example, like this: user_id in a model called Micropost will associate a micropost with the ID of an User model. Like this: r

  • Rails 3: Is it possible to access a model's attribute in a query? 2011-04-28

    Sorry if that question sounds strange, but I'm diving into Rails and I'm still learning the jargon. Basically, I'm trying to create a single-pass query that uses the value of one of the model's attributes in a calculation in the query (assuming that'

  • How to pass user credentials to sharepoint using SP Object Model instead of web service while uploading file 2010-12-02

    I want to upload files in a document library of sharepoint site (WSS 3.0) using c#, but the problem is that I want to allow only authorized users to upload file. I don't know how to pass user credentials using sharepoint object model. Is there a way

  • Rails after_create callback can't access model's attributes 2010-04-07

    I can't access my model's attributes in the after_create callback... seems like I should be able to right? controller: @dog = => 'brown', :gender => 'male') @dog.user_id = model: class Dog < ActiveRec

  • How do I pass a parameter into an access report programatically? 2008-12-29

    I've got an existing Access MDB. I'm adding a command button to an existing Form that runs an existing report. The change being made is that this button needs to pass in a parameter containing the ID of the record being reported on - currently the re

  • Passing parameter to query for Access database 2011-09-19

    I am using following code and trying to get data by given parameters. I donot know how to pass the parameter value to my query. Dim con As New OleDb.OleDbConnection Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String con.Connecti

  • Passing a parameter using RelayCommand defined in the ViewModel (from Josh Smith example) 2009-05-01

    I would like to pass a parameter defined in the XAML (View) of my application to the ViewModel class by using the RelayCommand. I followed Josh Smith's excellent article on MVVM and have implemented the following. XAML Code <Button Command="{Bindi

  • How can I pass a parameter to a Java Thread? 2009-05-18

    Can anyone suggest to me how I can pass a parameter to a thread? Also, how does it work for anonymous classes? --------------Solutions------------- You need to pass the parameter in the constructor to the thread object: public class MyThread implemen

  • Pass a parameter from one jsp to another using form.action 2009-08-05

    I have an ID that I need in the next jsp once the user click a button. I am trying to do the following: FirstJSP.jsp: function getSecond() { var frm = document.getElementById("frm"); frm.action = "**second.jsp?id=myId;"** frm.submit(); } ... form id=

  • Passing multiple parameter to PHP from Javascript 2009-10-21

    i am trying to Use this function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XM

  • Pass dynamic parameter 2010-01-31

    I want to pass dynamic parameter (UserName) from web application into silverlight . I know how I can do that in Silverlight 2.0 with Asp:Silverlight tag, however as in Silverlight 3.0 there is Object tag instead of Asp:Silverlight tag, I was wonderin

  • Can I pass a parameter directly to a .js file, and how do I get the value 2010-06-30

    This question already has an answer here: Pass vars to JavaScript via the SRC attribute 6 answers Passing parameters to JavaScript files 12 answers I want to pass a parameter to some javascript using a single line of code, like this: <script langu

  • How do I pass a parameter from one page into another in wordpress 2010-09-20

    Greetings: I am trying to pass a parameter from one page into another one. How do I do this? Is there a way when someone logs into the application, I do not want them to log in twice. I want the other page to know that this user is already logged in

  • How can I pass a parameter via submit button? 2010-09-26

    In my code for an mini online book store i have a following line repeating 5 times with different value for 'name' parameter <input name="JSP-2" type="submit" value="Buy"> On clicking the button Buy, the application redirects to a file buy.jsp

  • How do I pass a parameter to a JSP via a cross-context JSTL import? 2010-10-13

    I've come across a few other questions that describe a similar, but not identical situation, to mine. This question, for instance, shows pretty much the same problem, except that I'm not using portlets - I'm just using boring ol' JSP+JSTL+EL+etc. I h

  • Passing a parameter to a comparison function? 2010-11-01

    When using the STL sort algorithm on a vector, I want to pass in my own comparison function which also takes a parameter. For example, ideally I want to do a local function declaration like: int main() { vector<int> v(100); // initialize v with

  • Is there any way to pass unnamed parameter to stored procedure through SqlCommand (ADO.NET)? 2011-01-20

    I write a simple wrapper for sp calls using SqlCommand Type==StoredProcedure. I just want to pass parameter there without specifying its name. How can i do it? cmd.Parameters.Add(param) doesn't work, it gets only SqlParameter instance. Thank you for

  • how to pass a parameter by pressing a button 2011-05-18

    i have the situation: i'm showing many lines from the DB on the page. just creating dynamic lines (<% foreach (res in DBVar) %>). Every line has a button. every button use just 1 OnClick method. I really dont care of the name(value) of these bu

  • Passing a parameter to a variable in code C# 2011-05-20

    I am trying to use this program, but I would like to be able to pass a parameter where: DeleteOnReboot(@"C:\test.txt"); "C:\Text" is So I could call consoleapp.exe /C:\test2.exe So I would have a variable in code e.g. DeleteOnReboot(@"%VARIABLE%"); F

Copyright (C), All Rights Reserved.

processed in 0.127 (s). 11 q(s)