ruby - How does lambda function works in rails with an example from paperclip gem -
i had problem paperclip gem default_url
doesn't load after fingerprinted in production environment, code this:
class user # attachments paperclip - profile pic has_attached_file :profilepic_attachment, :styles => { thumb: '100x100#', square: '500x500#' }, :default_url => actioncontroller::base.helpers.asset_path("missing/default_user.png"), :preserve_files => true validates_attachment_content_type :profilepic_attachment, content_type: /\aimage\/.*\z/ end
note when rails c
in production , print out actioncontroller::base.helpers.asset_path("missing/default_user.png")
. fingerprinted version (correct version) printed out. default_user-fb34158daae99f297ad672c43bb1a4d3917d8e272b5f2254aa055392aa2faa94.png
.
however, when inspect browser, original /assets/missing/default_user.png
appeared.
i struggled long time until came across post, tells me change
:default_url => actioncontroller::base.helpers.asset_path("missing/default_user.png"),
to
:default_url => lambda { |image| actioncontroller::base.helpers.asset_path("missing/default_user.png") },
i wasn't sure happened, works. wonder lambda function
, when used in rails? also, passed in variable |image|
seems wasn't use in code. why that?
thanks!
Comments
Post a Comment