Ese10
Ese10

Reputation: 19

Ruby On Rails - Redirect_to |format| not working

I have a problem when I click a button to run some js file, rails throws an error saying: ActionController::UnknownFormat. and respond_to do |format| is highlighted

I have these 3 file paths

views -> file -> file1 -> create.js.erb
controllers -> file -> file1_controller.rb

views -> file -> files2 -> file2.html.erb

Inside file2.html.erb there is a button that says:

<%= button_to "Go To", 
  file_file1_create_path,
  params: {id: table.id},
  remote: true,
  class:"btn btn-outline-success" 
%>

Inside file1_controller.rb it says:

class File::File1Controller < FileController
  def create
    # a lot if code
    respond_to do |format|
      format.js
    end
  end
end

The request logs are:

Started GET "/file/..." for 127.0.0.1 at 2022-08-21 19:37:00 -0400

ActionController::RoutingError (No route matches [GET] "/file/..."):

Started POST "/file/file1/create" for 127.0.0.1 at 2022-08-21 19:37:24 -0400
Processing by File::File1Controller#create as HTML
  Parameters: {"authenticity_token"=>"[FILTERED]", "id"=>"1"}
  Item Load (0.5ms)  SELECT "items".* FROM "items" WHERE "items"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/file/file1_controller.rb:5:in `create'
Completed 406 Not Acceptable in 878ms (ActiveRecord: 0.9ms | Allocations: 6099)



ActionController::UnknownFormat (ActionController::UnknownFormat):

app/controllers/file/file1_controller.rb:23:in `create'

Upvotes: 0

Views: 198

Answers (0)

Related Questions