Rails Hotwire Cookbook
Turbo Drive-> Turbo Frames -> Turbo Stream ->
Turbo Drive = turbo link + ujs
good>
link_to
best>
button_to "" method: :delete, data: {turbo_confirm: ""}
form_submit ""
div id="foo" data-turbo-prement="true"
data: {rubo: false}
TurboFrames
lazy loading
turbo_frame_tag employee, loading: :lazy, src: ''
Turbo Drive = turbo link + ujs
good>
link_to
best>
button_to "" method: :delete, data: {turbo_confirm: ""}
form_submit ""
div id="foo" data-turbo-prement="true"
data: {rubo: false}
TurboFrames
lazy loading
turbo_frame_tag employee, loading: :lazy, src: ''
def index
@q = Employee.ransack(params[:q])
@employees = @q.result(distinct: true)
end
search_form_for data: {turbo_action: "advance", turbo_frame: :employees_list } do |f|
f.search_field: : first_name_or_last_name_or_email_cont, oninput: "this.form.requestSubmit()", autofocus: true
turbo_frame_tag :employees_list , data: {turbo_action: "advance"},target: "_top" do
div class="table-with-borders"
<td> <%= highlight employee.first_name, params[:query]
<th> <%=sort_link(@q, :first_name, 'First name')
<th> <%=sort_link(@q, :first_name, 'First name')
#employees/_employee.html.erb
[:first_name, :last_name].each do |attribute|
turbo_frame_tag attribute do
<strong> <%=attribute%>:</strong>
link_to (employee[attribute].presence || 'Edit'), [:edit, employee, attribute: attribute]
# employees/edit.html.erb
if params[:attribute].present?
=render "inline_attribute_form", employee: @employee
else
=render "form", employee: @employee
end
#/employees/5/edit?attribute=first_name
#employee/_inline_attribute_form.html.erb
turbo_frame_tag params[:attribute] do
form_with()
if params[:attribute].eql? 'first_name'
form.text_field :first_name, onfocusout: 'this.form.requestSubmit'/github.com/ yshmarov/hotwire-cookbook
阅读量: 1339
发布于:
修改于:
发布于:
修改于: