D
D
Denis2016-10-18 17:44:12
Ruby on Rails
Denis, 2016-10-18 17:44:12

How to update part of a page by submitting a form (Rails 5 and Turbolinks 5)?

when i send to action "filter" controller "homes":

def filter
  @comments = Home.where("name like ?", "%#{params[:name]}%")
  render :index
end

link:
<%= link_to 'filter', homes_filter_path(name:'an')%>

then the expected action happens: the comments are filtered and displayed on the page. If you do the same with a form:
<%= form_tag homes_filter_path, method: 'post', remote:true do %>
  <%= text_field_tag :name %> #в name => 'an'
  <%= submit_tag 'Submit'%>
<% end %>

in response from the server, the data comes but is not displayed on the page.
my routes.rb looks like this
root  'homes#index'
  #get/post сдеано для удобства, по одиночке тоже пробовал - эффект аналогичный
  get   'homes/filter' 
  post  'homes/filter'

The question is how to tell Turbolinks that the response to the request from the form should be shown without reloading the entire page?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
N. Bekseitov, 2016-10-18
@nbekseitov

A basic ajax form in Rails

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question