ruby-on-railsrubyregexactionviewactionviewhelper

Rails 4.2: Retrieve Files without Extension ( collection_check_box )


I have a list of pdf files passed through and displayed by Rails collection_check_box method...

<%= f.collection_check_boxes :upload_ids, Upload.where(file_type: ".pdf"), :id, :file_name do |b| %>
    <%= b.label do %>
    <%= b.check_box + b.text %>
    <% end %>
    <% end %>

How could I show the file name without the extension within this block of code?


Solution

  • You need to extract it manually :

    <%= b.check_box + File.basename(b.text,'.*') %>