0

Consider this

if params['image'].nil?
  1. In html's case, I used the above and it checked the presence of file and hence i changed the path accordingly. How can I check it in erb?

  2. I have a <%= f.file_field :IMAGE %> in my code and when I click on the submit button, I have to store my image in a database and use it or i want to store the images in files and store the path in database so i can display the image later.

How can I do this?

waldyr.ar
  • 14,424
  • 6
  • 33
  • 64
usr
  • 303
  • 1
  • 3
  • 8

2 Answers2

0

You should checkout some gems like Paperclip or Carrierwave, as well as the Railscast for Paperclip and the Railscast for Carrierwave.

Vapire
  • 4,568
  • 3
  • 24
  • 41
0

1) You can check wether params['image'] is nil or not, you just have to follow the best practice to store it in an instance that I'm going to call @image, although you can be a maverick and use params['image'] if you want.

<% unless @image.nil? %>
  <!-- Code here -->
<% end %>

OR

<% if @image.nil? %>
  <!-- Code here -->
<% else %>
  <!-- Code here -->
<% end %>

2) You can use a gem to support you like Dragonfly or Paperclip. Check this Paperclip vs Carrierwave vs Dragonfly's Question out!

Community
  • 1
  • 1
waldyr.ar
  • 14,424
  • 6
  • 33
  • 64