I am using a partial that is rendered in two forms belonging to two different controllers as below:
update_user.html.erb
<%= form_with model: @user,
url: {
controller: :profile,
action: :update_user
},
method: :post,
local: true do |f| %>
<%= render partial: 'shared/user_registration_fields', locals: { f: f, profile: @profile } %>
<%= f.submit 'Confirm' %>
<% end %>
new_user.html.erb
<%= form_for @user,
url: {
action: :register_user
},
method: :post,
local: true do |f| %>
<%= render partial: 'shared/user_registration_fields', locals: { f: f, profile: @profile } %>
<%= f.submit 'Confirm' %>
<% end %>
One field in partial is as below:
partial.html.erb
<%= f.fields_for :profile, profile do |prform| %>
<%= prform.label :date_of_birth, 'DOB' %><br />
<%= prform.text_field :date_of_birth, { class: 'datepicker', title: "Date_of_birth", value: (f.object.date_of_birth.strftime("%d-%m-%Y") if f.object.date_of_birth.present?) } %>
The image is rendered using jquery as below:
$( ".datepicker" ).datepicker({
showOn: "button",
buttonImage: "assets/form_images/calendar.png",
buttonImageOnly: true,
buttonText: "Select date of birth",
dateFormat: 'dd-mm-yy',
});
The first form is in the following path -> app/views/profile/update_user.html.erb The second form is in the following path -> app/views/login/new_user.html.erb The partial is in the following path -> app/views/shared/_partial.html.erb
Now the image assets/form_images/calendar.png
is being shown in this file new_user.html.erb
but not in this update_user.html.erb
. When I checked the image url from browser, for new_user.html.erb
it is assets/form_images/calendar.png
which is correct but for update_user.html.erb
it is profile/assets/form_images/calendar.png
which is wrong. Why is it showing like this? What am I doing wrong here?