Renaming uploaded files with Carrierwave

Well, another problem with your random filename generator is that it’s possible to have collisions isn’t it? You could possibly generate a filename that was already generated. One way to go about it would be to somehow generate a hash based on unique properties of the image, like file path. An example, from the carrierwave … Read more

How do you declare a Rake task that depends on a parameterized task?

Args are passed down through the call stack. You just need to make sure your top-level task captures all the arguments all of the dependencies require. In your case you’ll want to put first_name and last_name on the send_letter task. Here is an example that shows named arguments defined elsewhere flowing into the dependency (even … Read more

Ruby – determining method origins?

Object#method returns a Method object giving meta-data about a given method. For example: > [].method(:length).inspect => “#<Method: Array#length>” > [].method(:max).inspect => “#<Method: Array(Enumerable)#max>” In Ruby 1.8.7 and later, you can use Method#owner to determine the class or module that defined the method. To get a list of all the methods with the name of the … Read more

Passing param values to redirect_to as querystring in rails

The ‘Record’ form of redirect_to uses the second argument only for the response status. You’ll have to use another form of redirect_to, like the ‘String’ form. e.g.: redirect_to thing_path(@thing, :foo => params[:foo]) which will work for nested params[:foo] params like you mentioned. Or, as Drew commented below, you can use polymorphic_url (or _path): redirect_to polymorphic_path(@thing, … Read more

Ruby formatting for ordinals: ‘1’ as ‘1st’, ‘2’ as ‘2nd’ etc

Looks like you are looking for ordinalize: The Ruby on Rails framework is chock full of interesting little nuggets. Ordinalize is a number extension that returns the corresponding ordinal number as a string. For instance, 1.ordinalize returns “1st” and 22.ordinalize return “22nd”. Example: place = 3 puts “You are currently in #{place.ordinalize} place.” Result: You … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)