When I'm creating a product with this URL http://localhost:3000/versions/new?product_id=1 and the validations fails, Rails isn't keeping the product_id in the URL
And I get this URL http://localhost:3000/versions
I need that parameter to keep the filter by product and for the links like "back", but I don't want to use "session" or "redirect" to do that.
I don't understand why Rails doesn't keep the URL. I have used CakePHP before with forms, parameters and validations like that and I'm sure that I didn't face that problem.
def create
@version = Version.new(version_params)
respond_to do |format|
if @version.save
format.html { redirect_to @version, notice: I18n.t('controllers.versions.created_successfully', default: 'Version was successfully created.') }
format.json { render :show, status: :created, location: @version }
else
format.html { render :new }
format.json { render json: @version.errors, status: :unprocessable_entity }
end
end
end
Thank you.
Aucun commentaire:
Enregistrer un commentaire