如果param [:date]!= nil,我想渲染format.html,如果不是nil,則渲染.js。Rails - 用控制器中的ajax請求渲染html
我的link_to:
<%= link_to place_path(place, date: params[:date]), id: "#{place.id}", remote: true, authenticity_token: true, data: { title: place.city }, target: "_blank" do %>
我的控制器:
class PlacesController < ApplicationController
def show
if params[:date] == nil
respond_to do |format|
format.html {
preparation_of_instance_variables_for_show_view
}
format.js { }
end
else
respond_to do |format|
format.html {
preparation_of_instance_variables_for_show_view
}
format.js {
render format: 'html' # <= where I want to render format.html
}
end
go_to_show_view
end
end
private
def preparation_of_instance_variables_for_show_view
@place = Place.find_by_id(params[:id])
if params[:date].present?
@guests = Booking.accepted.where(place: @place, date: Date.parse(params[:date])).map(&:guest)
end
end
我怎樣才能重定向到format.html只是爲了這個案子?
我有show.js.erb,我使其當我在第一種情況下,但我想渲染show.html.erb對於第二種情況的js要求 –