Answer the question
In order to leave comments, you need to log in
Why does the view not see what is in the variable?
Hello, tell me how to deal with the variable.
I'll start from the beginning. There are for example 100 div blocks on the site. Each div is a place in the cinema. When clicking on one of the blocks, its unique id is written to the $arr variable. Thus, I implement the functionality for ordering and selecting several places for booking at once.
$arr = [];
$link = $(location).attr('href').slice(36);
$('.btn-warning').each(function() {
$place_id = $(this).attr('id');
$arr.push($place_id);
});
$.ajax({
url: "/film_sessions/" + $link,
type: "get",
data: { data_value: JSON.stringify($arr) }
});
before_action :get_booking_place_array, only: [:show]
def get_booking_place_array
@test_test = params[:data_value]
puts "----------------------------------------------------------------------"
puts @test_test
puts "----------------------------------------------------------------------"
end
def show
...
@test_test = []
end
<div id="data2">
<% @test_test.each do %>
<h1>hello</h1>
<% end %>
</div>
["place_5","place_6","place_32"]
Answer the question
In order to leave comments, you need to log in
Why do you need before_action for one action?
Try to do this in show:
Or in the view, check your
<% if @test_test.present? %>
.....
<% end %>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question