0

I have the following code in messages.html.erb.

<% vars = request.query_parameters
   @templates = session[:templates]
%>

<h3>There are <%= @templates.count %> templates</h3>
<form method='post' action='http://localhost:80/text.php'>

 <select name="template">
   <% @templates.each do |t| %>
      <option name='<%=t.name %>'><%= t.name %></option>
   <% end %>
 </select>
  <br /><br />
  <input type='submit' value='Submit' />
</form>

Now, in application_helper.rb, there is a method link_to_phone wherein we have:

  session[:templates] = Template.all
  link_to(h(phone), message_path(phone: phone, id: contact.id, page: 'contacts'), title: phone)

where message_path takes us to messages.html.erb.

If the section( where I have omitted the phone, id, and page fields as they do not play a part here) :

 <select name="template">
   <% @templates.each do |t| %>
      <option name='<%=t.name %>'><%= t.name %></option>
   <% end %>

is omitted from messages.html.erb, I get the statement that in my case there are 3 templates stored in the session by the link_to_phone definition. If that section is included in the code then I get a Cookie Overflow. I'm not using cookies to my knowledge, but instead thought I was using the session. I have another statement very similar to this in my view/template/index.html.erb wherein I loop through the @templates and show the name, msg, and subject, using this exact same idea except putting the separate template name, msg, and subject into a table with no problem.

What am I missing here that is causing this 'Cookie' problem?

John Wooten
  • 685
  • 1
  • 6
  • 21

1 Answers1

1

Sessions are actually cookies, but the information is stored at the server side and a cookie is passed to the user's browser with a session id. You got a limit of 4KB for entire cookie, including name, value, expiry date.

But Rails stores session information by default at the cookie_store, you can solve this one by changing your session_store, you can use active_record_store for instance.

See: Cookie overflow in rails application?