I am trying to build a index page with a form displayed inside a modal. After the form is submitted with POST action as JS, triggers #create
action that responds with redirect_to
action #index
also as JS, like this
def create
@output = Output.new(output_params)
respond_to do |format|
if @output.save
format.html { redirect_to @output, notice: 'Output was successfully created.' }
format.json { render :show, status: :created, location: @output }
format.js { redirect_to production_line_path @output.machine.production_line, machine_id: @output.machine_id, format: :js }
else
format.html { render :new }
format.json { render json: @output.errors, status: :unprocessable_entity }
end
end
end
My problem is that this gives an error with the following description
Security warning: an embedded <script>
tag on another site requested protected JavaScript. If you know what you're doing, go ahead and disable forgery protection on this action to permit cross-origin JavaScript embedding.
Completed 422 Unprocessable Entity in 35ms (Views: 27.2ms | ActiveRecord: 1.5ms)
ActionController::InvalidCrossOriginRequest (Security warning: an embedded <script>
tag on another site requested protected JavaScript. If you know what you're doing, go ahead and disable forgery protection on this action to permit cross-origin JavaScript embedding.):
I am not sure if I am trying to do this the wrong way. Would I have to change response for JS to not redirect, but rather render from the same controller action #create
?