I am new to rails. My project requirement is to load a portion of element on the same page with all elemnts as it is before. For this I have used a new route in routts.rb like
get "/sell_used_car/edit", to:"sell_used_car#edit", as: :sell_used_car_edit
The view of my pain page i.e. of "views/sell_used_car/new.html.erb" is like:
<%= link_to "Change Email",sell_used_car_edit_path, remote: true %>
<div id = "content"></div>
In the sell_used_car_controller.rb I have included the codes like:
def edit
respond_to do |format|
# format.html{}
format.js
end
end
In the above code if I using the line format.html{}, I got error like : "SellUsedCarController#edit is missing a template for this request format and variant. request.formats: ["text/html"] request.variant: []"
If I commented out that line I got the error like : "ActionController::UnknownFormat"
I have placed the file edit.js.erb and _edit.html.erb in right location and that looks like
edit.js.erb
$('#content').html("<%= escape_javascript(render :partial => 'edit')%>");
_edit.html.erb
<%= form_with do |form| %>
<div class="d-flex align-items-center justify-content-center flex-column">
<div class="mb-3">
<%= form.label :Enter_Your_New_Email%>
<%= form.text_field :email, placeholder: "xyz@abc.com", class: "form-control"%>
</div>
</div>
<%end%>
I know if I include the line format.html{}, the error comes because it can't find the .html.erb file. But I have alredy defined in the edit.js.erb that it sholud render to a partail file. But unfortunately it can't. Also I have used only this line in the controller like
def edit
respond_to do |format|
# format.html{}
format.js {render :edit}
end
end
But the same error comes as "ActionController::UnknownFormat". I am really stuck here.
Thanks in advance.