How to use send_file in RoR
I'm very new to RoR and am trying to use send_file to have users download and view files that were uploaded by other users. I want to have a link on the project show page for each of the uploaded files. For now I am uploading the files using carrierwave and storing them in public/uploads/permit/avatar/permit_id/file. After going through much documentation I can't seem to figure out exactly what code to put into开发者_StackOverflow社区 the model view and controller to get the links to show up on the show page. Can some one please help me with what code to put where.
if you want allow only authorithed users download files then you should set other path than public
, something like:
private/uploads/permit/avatar/permit_id/file
and use something like send_file avatar.uploader_field.file
in controller action then in views:
link_to "avatar", path_to_controller_action
For everyone:
link_to "avatar", avatar.uploader_field.url
or
link_to "avatar", avatar.uploader_field.path
in views
精彩评论