Monday, May 20, 2024
98
rated 0 times [  99] [ 1]  / answers: 1 / hits: 29387  / 11 Years ago, fri, april 26, 2013, 12:00:00

I'm trying to submit a form in rails without refreshing the page afterwards. I've been looking around online, but it seems that adding :remote => true doesn't seem to change my form the way I thought it would. Right now I have each question having a number of answers, and each one is connected to a radio button, but I've hidden the radio button so clicking on the label itself submits the form. Does the page refresh as a result of the radio button form submission? I'm really not sure, and would appreciate any help at this point...



<%= form_for(uanswer, :remote => true) do |f| %>
<% answers.each_with_index do |answer, i| %>
<% unless answered_flag %>
<%= f.radio_button :answer_id, answer.id, :class => radio hide,
:onclick => this.form.submit(); %>
<% end %>
<%= f.label :answer_id, answer.answer, :class => answer,
:value => answer.id %>
<% end %>


The generated HTML form looks more or less like this:



<form accept-charset=UTF-8 action=/uanswers class=new_uanswer 
data-remote=true id=new_uanswer method=post><div
style=margin:0;padding:0;display:inline><input
name=utf8 type=hidden value=✓><input name=authenticity_token
type=hidden value=PY5ACVmrvDnt/iYF8RK6O7tDKAn2G2dFdLeBNZw5MJ4=></div>
</form>

More From » ruby-on-rails

 Answers
25

The remote=>true isn't doing anything for you right now as you are bypassing rails with the this.form.submit(). You need to submit the form asynchronously. See Submit form in rails 3 in an ajax way (with jQuery) for a solution to a similar question.


[#78591] Thursday, April 25, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaleyv

Total Points: 259
Total Questions: 99
Total Answers: 107

Location: Saint Helena
Member since Tue, Nov 3, 2020
4 Years ago
;