Reputation: 25
I have a method: index that gets the value of the checkbox per post
def index
session[:post] = params[:checkbox_array]
end
The value of params[:checkbox_array]
is:
{"2m"=>"1", "2"=>"2", "3m"=>"3", "3"=>"4", "4"=>"5", "4a_5d"=>"6", "5"=>"7", "6m"=>"8", "6"=>"9", "7m"=>"10", "7"=>"11"}
When I click on button to make the post I am redirect to page interval_identification.html
I want to get the variable value @post
on method interval_identification
on controller.
I can not call the index
method inside the interval_identification
method because I'm going to do a get in the interval_identification
and the value of the @post
variable should be the same when the post was done in the index
.
I was researching and saw that the solution would be to save the @post
value of the method index
in the session, and then reading that value and assigning it to a variable in the interval_identification
method, but I do not know how to do that, can you help me?
def interval_identification
@post = session[:post]
end
I tried to do it. but when I show the @post value on interval_identification view, the value is blank
interval_identification.html.erb:
<a><%= @post %></a>
Upvotes: 2
Views: 736
Reputation: 5335
Accessing the session is pretty straight forward:
def index
session[:post] = params[:checkbox_array]
end
def interval_identification
#session[:post] should be here waiting for you!
end
Upvotes: 1