Everything was fine before adding Bootstrap to the project. Now I am getting ActionController::UnknownFormat
error. I was using jquery in my project before(added with yarn). But when installing Bootstrap, I also installed jquery for it with a gem. Maybe there can be a problem in there. Thanks for helping.
comments_controller.rb
def create
@book = Book.find(params[:book_id])
@comment = @book.comments.create(comment_params)
respond_to :js
end
create.js.erb
$(".comment").append("<%= escape_javascript(render(@comment))%>");
_comment.html.erb
<p><strong><%= comment.title %></strong> | <%= comment.commenter %></p>
<p><%= comment.content %></p>
Console output
app/controllers/comments_controller.rb:17:in `create'
Started POST "/books/2/comments" for 127.0.0.1 at 2020-10-30 14:45:28 +0300
Processing by CommentsController#create as HTML
Parameters: {"authenticity_token"=>"PT6Go3HJURAbU7olooyAVa7j5Xna9NlfulH62DPt/JbcfRXw1cWEujnfNhhjmafyncB9tMkefUKT09z+d0ryiQ==", "comment"=>{"title"=>"a", "content"=>"s", "commenter"=>"user", "approved"=>"false"}, "commit"=>"Create Comment", "book_id"=>"2"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Book Load (0.2ms) SELECT "books".* FROM "books" WHERE "books"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
↳ app/controllers/comments_controller.rb:15:in `create'
(0.1ms) BEGIN
↳ app/controllers/comments_controller.rb:16:in `create'
Comment Create (0.4ms) INSERT INTO "comments" ("title", "content", "approved", "book_id", "created_at", "updated_at", "commenter") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["title", "a"], ["content", "s"], ["approved", false], ["book_id", 2], ["created_at", "2020-10-30 11:45:28.088322"], ["updated_at", "2020-10-30 11:45:28.088322"], ["commenter", "utkucb"]]
↳ app/controllers/comments_controller.rb:16:in `create'
(0.8ms) COMMIT
↳ app/controllers/comments_controller.rb:16:in `create'
Completed 406 Not Acceptable in 9ms (ActiveRecord: 1.8ms | Allocations: 5589)
ActionController::UnknownFormat (ActionController::UnknownFormat):
app/controllers/comments_controller.rb:17:in `create'
I'm accessing CommentsController#create
in books/show.html.erb with this form.
<%= form_with(model: [ @book, @book.comments.build ], local: false) do |form| %>
<p>
<%= form.label :title %><br>
<%= form.text_field :title %>
</p>
<p>
<%= form.label :content %><br>
<%= form.text_area :content %>
</p>
<%= form.hidden_field :commenter, value: current_user.username %>
<%= form.hidden_field :approved, value: false %>
<p>
<%= form.submit %>
</p>
<% end %>
My Rails version is Rails 6.0.3.4
and Bootstrap version is 5.0.0.alpha1
. I used this tutorial to use jquery and everything was fine. Than used this to add Bootstrap.