I created a simple_form in my Ruby on Rails app. It's working fine except when there is an error in the form, and the form is reloaded, at this moment I lose the params in the url.
(I Already read Keep params after render Ruby on Rails and Rails 3 Render => New with Parameter)
Here is the controller code:
def new
@parts = Part.where(id: params[:part_id])
@part = params[:part_id]
@traveller = Traveller.new
end
def create
if @traveller.save
redirect_to edit_part_path(:id => @traveller.part_id)
flash[:notice] = t('alert.create')
else
@part = [:traveller][:part_id]
@parts = Part.where(id: params[:part_id])
render :action => "new", :part_id => @part
end
end
And here is the view code
<%= simple_form_for @traveller, html: { class: "sigPad"} do |f| %>
<%= f.input :name %>
<%= f.input :surname %>
<%= f.input :part_id , label: 'part',readonly: true, input_html: {id: 'part_id', value: params[:part_id] }%>
<% end %>
I check if the part_id is submited and it is.
My question is how can I keep the part_id in params when the page is reloaded. Note