Note that there are some explanatory texts on larger screens.

plurals
  1. POAuthenticity Token being created differently when using render_to_string
    primarykey
    data
    text
    <p>I'm generating a small form through <code>render_to_string</code> and for some reason the CSRF token is not being generated correctly (i.e. it's different from the header and the user is logged out on submit, along with a "Can't verify CSRF token" on the logs). Here's the relevant code:</p> <p>Controller:</p> <pre><code>def publish @question = @event.questions.find(params[:id]) @question.update_attribute(:published, true) unless @question.published? Pusher[@event.to_param].trigger('new_question', question: render_question) redirect_to event_path(@event) end private def render_question render_to_string('questions/_unanswered_question', locals: {question: @question}, layout: false) end def fetch_event @event ||= current_user.events.find(params[:event_id]) end </code></pre> <p>I'm using Pusher, but you can assume this is just being rendered on the page with this Javascript:</p> <pre><code>$("#questions").append(data.question); // data is what I send from Pusher. </code></pre> <p>And finally, the partial being rendered:</p> <pre><code>.answer = form_for [@event, question, question.answers.new] do |f| %h2 = question.title %ul - (1..5).each do |n| - if question.send("answer_#{n}").present? %li = f.radio_button :option, n, id: "q_#{question.id}_answer_option_#{n}" = f.label question.send("answer_#{n}"), for: "q_#{question.id}_answer_option_#{n}" %p = f.submit "Answer" </code></pre> <p>This works just fine without being appended to the page, but rendered within the layout. Note that this is not a remote form.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload