Here is a way to download a file without using any gem and just using rails,
Solution: =>
def create @photo = Photo.new(photo_params) uploaded_io = params[:photo][:photo] File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'wb') do |file| file.write(uploaded_io.read) end if @photo.save flash[:success] = "The photo was added!" redirect_to root_path else render 'new' end end def upload uploaded_io = params[:person][:picture] File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'wb') do |file| file.write(uploaded_io.read) end end
And your form.html.erb in the views should contain this, it's very simple,
<%= form_for @photo do |f| %> <%= f.file_field :photo %> <div class="actions"> <%= f.submit "Upload" %> </div> <% end %>
and finally, the model must have
has_attached_file :image
###################################################. #### Now you can upload any file.
Thanks. Play with the rails.
Use <video_tag> for viewing video files. Use <audio_tag> for viewing audio files. Use <object>"link"</object> for viewing PDF or DOC files.
source share