Я пытаюсь сохранить номера мест в экземпляре моего контроллера, разместив его с помощью AJAX. После нажатия на кнопку отправки заголовки ответа говорят STATUS 200 OK
, а при нажатии кнопки «Просмотр (ответ)» данные отображаются на той же странице. Мой контроллер Билеты метод SEAT
def seat
@seats = params["seat_number"]
end
rout.rb file
get '/tickets/seat' => 'tickets#seat', as: 'seat'
post '/tickets/seat' => 'tickets#seat'
место. html .erb
<%= form_with(url: "tickets/seat",:html => {id:'seat'}, local: true) do |f| %>
<% plane = Trip.find(params[:trip_id]).aeroplane %>
<% erow = plane.e_row %>
<% ecol = plane.e_col %>
<% brow = plane.b_row %>
<% bcol = plane.b_col %>
<% frow = plane.f_row %>
<% fcol = plane.f_col %>
<div class="text-center"><strong><%= plane.name %></strong></div>
<div class="plane">
<div class="cockpit">
<h1>Please select a seat</h1>
</div>
<div class="exit exit--front fuselage"></div>
<ol class="cabin fuselage">
<!-- Economy Class Configuration -->
<div class='text-center seat-class'><strong>Economy Class</strong></div>
<% (1..erow).each_with_index do |i| %>
<% alpha = '@' %>
<li class="row">
<ol class="seats" type="Economy">
<% (1..ecol).each do %>
<% alpha = alpha.next %>
<% if Trip.find(params[:trip_id]).tickets.where("seat_class LIKE ? AND seat_number LIKE ?", "Economy","#{alpha}"+"#{i}").count==1 %>
<li class="seat eco">
<%= check_box_tag("seat_number[]","Economy."+"#{alpha}"+"#{i}", false, disabled: true) %>
<%= label("seat_number", "#{alpha}"+"#{i}",:value => "Economy."+"#{alpha}"+"#{i}") %>
</li>
<% else %>
<li class="seat eco">
<%= check_box_tag("seat_number[]","Economy."+"#{alpha}"+"#{i}") %>
<%= label("seat_number", "#{alpha}"+"#{i}",:value => "Economy."+"#{alpha}"+"#{i}") %>
</li>
<% end %>
<% end %>
</ol>
</li>
<% end %>
<!-- First Class Configuration -->
<div class='text-center seat-class'><strong>Premium Economy Class</strong></div>
<% (1..frow).each_with_index do |j| %>
<% alpha = '@' %>
<li class="row">
<ol class="seats" type="Premium Economy">
<% (1..fcol).each do %>
<% alpha = alpha.next %>
<% if Trip.find(params[:trip_id]).tickets.where("seat_class LIKE ? AND seat_number LIKE ?", "Premium Economy","#{alpha}"+"#{j}").count==1 %>
<li class="seat pre">
<%= check_box_tag("seat_number[]","Premium Economy."+"#{alpha}"+"#{j}", false, :disabled => true) %>
<%= label("seat_number", "#{alpha}"+"#{j}",:value => "Premium Economy."+"#{alpha}"+"#{j}") %>
</li>
<% else %>
<li class="seat pre">
<%= check_box_tag("seat_number[]","Premium Economy."+"#{alpha}"+"#{j}") %>
<%= label(:seat_number, "#{alpha}"+"#{j}",:value => "Premium Economy."+"#{alpha}"+"#{j}") %>
</li>
<% end %>
<% end %>
</ol>
</li>
<% end %>
<!-- Business Class Configuration -->
<div class='text-center seat-class'><strong>Business Class</strong></div>
<% (1..brow).each_with_index do |k| %>
<% alpha = '@' %>
<li class="row">
<ol class="seats" type="Business">
<% (1..bcol).each do %>
<% alpha = alpha.next %>
<% if Trip.find(params[:trip_id]).tickets.where("seat_class LIKE ? AND seat_number LIKE ?", "Business","#{alpha}"+"#{k}").count==1 %>
<li class="seat bus">
<%= check_box_tag("seat_number[]","Business."+"#{alpha}"+"#{k}", false, {:disabled => true}) %>
<%= label("seat_number", "#{alpha}"+"#{k}",:value => "Business."+"#{alpha}"+"#{k}") %>
</li>
<% else %>
<li class="seat bus">
<%= check_box_tag("seat_number[]","Business."+"#{alpha}"+"#{k}") %>
<%= label("seat_number", "#{alpha}"+"#{k}", :value => "Business."+"#{alpha}"+"#{k}") %>
</li>
<% end %>
<% end %>
</ol>
</li>
<% end %>
</ol>
<div class="exit exit--back fuselage"></div>
</div>
<%= f.submit('confirm seats') %>
<% end %>
<div class = "ticket">
<%= @seats %>
</div>
приложение. js
$(document).on('turbolinks:load', function(){
$('#seat').submit(function(e) {
e.preventDefault()
var valuesToSubmit = $(this).serialize();
var qstring = location.search;
console.log(valuesToSubmit);
$.ajax({
type: "POST",
url: '/tickets/seat'+ qstring, //sumbits it to the given url of the form ?trip_id=1
data: valuesToSubmit,
dataType: "HTML" // you want a difference between normal and ajax-calls, and json is standard
}).done(function(data){
console.log("success", data);
});
return false; // prevents normal behaviour
});
});
предварительный просмотр ответа
Может кто-нибудь сказать, почему мои данные не сохраняются в экземпляре контроллера переменная