Carrierwave how to get the file extension

前端 未结 2 1184
忘了有多久
忘了有多久 2021-02-05 12:53

I\'m developing a Ruby on Rails application that requires file uploading/downloading. For the upload part i used the gem carrierwave since it\'s very easy to use and flexible. T

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 13:39

    Once you have uploaded a file, the name is stored in the database. This also includes the extension. Assuming you have a User model with an uploader mounted as asset, then you can get it as:

    user.asset.file.extension
    

    As for sending it to the user, if you call user.asset_url, it will give you the URL where the file is uploaded. The user can use that link to get the file. Or am I misunderstanding what you mean by "send the file to a user"?

提交回复
热议问题