(I've removed working code part such as controller file and javascript to minimize question size as suggested in the chat. And I can add if required by anyone)
I followed this tutorial to upload image (worked successfully with some syntax modification). But when I integrated the code to member registration form, everything upto image preview is working, but photo is not uploading to the predefined directory.
Working part of code
uploadfile.html.erb
<h1>File Upload</h1>
<%= form_tag({:action => 'uploadFile'}, :multipart => true) do %>
<p><label for="upload_file">Select File</label> <%= file_field 'upload', 'datafile', :class => 'filen btn btn-danger'%></p>
<div class="upload-preview">
<img alt="your image"/>
</div>
<br><br />
<%= submit_tag "Upload" %>
<% end %>
Not working part of code (only uploading part. Works fine upto previewing image)
Now I integrate this code with my member reg form as below, by copy pasting form_tag contents without {} brackets in form_for to convert form_tag to form_for.
_form.html.erb
<div class="input-group">
<%= form_for(@member, :action => 'uploadFile', :multipart => true) do |f| %>
<p><label for="upload_file">Select File</label> <%= file_field 'upload', 'datafile', :class => 'filen btn btn-danger'%></p>
<div class="upload-preview">
<img alt="your image"/>
</div>
<div class="field">
<%= f.label :member_code %><br>
<%= f.text_field :member_code %>
</div>
So many fields and labels
<div class="actions">
<%= f.submit %>
</div>
<% end %>
</div>
members_controller.rb (Here, I copy paste the def uploadFile part from upload_controller.rb)
def index
@members = Member.all
end
def uploadFile
post = Member.save(params[:upload])
render :text => "File has been uploaded successfully"
end
def member_params
params.require(:member).permit(:member_code, :emp_code, :name, :father_name, :dob, :doe, :age, :caste, :religion, :residing_year, :nominee, :relation, :income_amt, :permanent, :off_add1, :off_add2, :off_add3, :mem_cancellation, :no_shares, :registration_date, :share_amt, :salary_head, :record_status, :sex, :mem_any_society, :occupation, :application_no, :dor, :kannada_name, :date_of_death, :date_of_inactive, :res_kan_add1, :res_kan_add2, :res_kan_add3, :kannada_nominee)
end
end
The preview part somehow working without creating new javascript file for member model.
From what I understand, When I press create member button, the file is not uploading to the predifined public/data directory. Even after I mention :action => 'uploadFile', in the view, why it is not working, when other things up-to preview image works fine. I think I have to add upload inside create action itself, but don't know what exactly to add. Please help me.