Skip to content

Instantly share code, notes, and snippets.

@mfifth
Created January 22, 2025 21:30
Show Gist options
  • Save mfifth/eaf89dded62fab0a3bef18fb74398184 to your computer and use it in GitHub Desktop.
Save mfifth/eaf89dded62fab0a3bef18fb74398184 to your computer and use it in GitHub Desktop.
#/app/views/surveys/create_answer.js.erb
$("#survey-#{@survey.id}").html("<div><p>You have submitted the form successfully!</p></div>");
alert('what the fuck');
console.log('why is this working.');
# Controller action
def create_answer
@survey = Survey.find(params[:survey_id])
@survey.answers.create(agree: params[:agree])
respond_to do |format|
format.js { render layout: false }
end
end
# Form tag from view
<div class="survey-answers" id=<%= "Survey-#{survey.id}" %>>
<%= form_tag('/create_answer', multipart: true, local: false, remote: true, method: :post) do %>
<%= label_tag "Do you agree?" %>
<%= radio_button_tag :agree, true, 'checked' %>
<%= label_tag "Do you disagree?" %>
<%= radio_button_tag :agree, false, 'checked' %>
<%= hidden_field_tag :survey_id, survey.id %>
<%= submit_tag 'Submit' %>
<% end %>
</div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment