-1

I want to add a file/folder browsing button in my rails application using simple_form gem. How do I do it? In simple_form documentation it is not mentioned.

Edit: File browse is mentioned in the documentation. But how to browse folders is not mentioned. Currently the only way I think possible is extract the folder from the file path. But what if there are no files present in the folder?

Sreeraj Chundayil
  • 5,548
  • 3
  • 29
  • 68
  • It's right there in the documentation https://github.com/plataformatec/simple_form#available-input-types-and-defaults-for-each-column-type – Deepak Mahakale Nov 07 '16 at 14:38
  • @Deepak: Yes file I noticed after you mentioned. But folder is missing. Currently I have to have some file in the directory from the file path I extract the directory path. Is there any easier way? – Sreeraj Chundayil Nov 09 '16 at 15:27
  • I think everyone reading this question is a little confused about what you're trying to accomplish. Are you trying to allow the user to upload an entire folder of files? – Chris Peters Nov 09 '16 at 15:48
  • @ChrisPeters: No, User selects a folder and I will dump a file into that folder. But folder selection is not found in simple_form documentation. It has file method. But if I don't have any file in target folder, I can't select that folder. – Sreeraj Chundayil Nov 09 '16 at 15:49
  • I think that you're having a lot of trouble because what you're trying to accomplish is not possible with an HTML `input` element. – Chris Peters Nov 09 '16 at 15:56
  • @ChrisPeters: What is the solution? Any alternative? – Sreeraj Chundayil Nov 09 '16 at 15:57
  • The most common solution is to provide a download link with instructions to right-click and "Save as...." Another is to have your server respond with headers that force the user to pick a folder and download a file. You could also possibly author a browser plugin that your users must install before using your web app. You'd need to do that for each browser because their APIs may be a little different. (I've never done that before however.) This 3rd solution is not realistic in my opinion if you want for your users to actually like you. – Chris Peters Nov 09 '16 at 16:03
  • I must also add that the server headers don't necessarily force the user to pick a folder. Some browsers may just instantly dump the file into their default download folder. – Chris Peters Nov 09 '16 at 16:04
  • @ChrisPeters: Why is browsing a file allowed but folder? – Sreeraj Chundayil Nov 09 '16 at 16:07
  • The point of a file input is to pick a file to upload to the server, not to pick a destination for downloads. You can't "upload" a folder. – Chris Peters Nov 09 '16 at 16:59

1 Answers1

4

You would do:

f.input :somename, as: :file
Anthony
  • 15,435
  • 4
  • 39
  • 69