I was already able to replace the posts using AJAX upon submitting the form. The problem though, is that the URL is not updating to include the params I added.
When I click on Submit, the values are passed to the controller. I can call params[:tags]
and it will return the IDs. However, the URL is still localhost:3000/posts/:id
and it didn't include the tag_ids.
Here are the affected files:
posts_controller.rb
:
def show
@posts = get_posts
respond_to do |format|
format.js
format.html
end
end
posts/show.html.haml
:
#posts
= render "posts", { posts: posts }
= form_tag url_for(:only_path => false), method: :get, remote: true, id: "posts-form" do
@tags.each do |tag|
= check_box_tag "tags[]", tag[:id]
= tag[:name]
= submit_tag "Filter"
posts/show.js.erb
:
$('#posts').html("<%= j (render 'posts', posts: @posts) %>")
Aucun commentaire:
Enregistrer un commentaire