jquery - for_form increment issue increment object -


i overlooking has me stumped....i have form display survey (it rendered in a partial) , using :remote => true pass controller (update) thru , ajax call via jquery, when render view via js.erb replace question next question , id next id render in original form (in hidden fields) thats not doing job first display after submit renders next question text id not incrementing , next submit call submitting first record. there js command increment in erb.

my code shown here below

<%= form_for(@category, :remote => true)  |f| %> <ul id='questionarea'> <%=@current_question %> </ul> <div id = 'hidden_field_usr' > <%=f.hidden_field :user_id, {:value => params[:id]}  %> </div> <div id = 'hidden_field_question' > <%=f.hidden_field :question_id, {:value => @current_question_id} %> </div>  <%=f.fields_for @answer |a| %>      <ul id= 'answerarea'>     <%= a.radio_button(:agree , 5) %>     <%= a.label(:agree_5, "i agree ") %>     <%= a.radio_button(:agree , 4) %>     <%= a.label(:agree_4, "i agree ") %>     <%= a.radio_button(:agree , 3) %>     <%= a.label(:agree_3, "i kind of agree ") %>     <%= a.radio_button(:agree , 2) %>     <%= a.label(:agree_2, "i disagree ") %>     <%= a.radio_button(:agree , 1) %>     <%= a.label(:agree_1, "i completly disagree ") %>        statement is:      <%= a.radio_button(:importance , 3) %>     <%= a.label(:importance_3, "incredibly important ") %>     <%= a.radio_button(:importance , 2) %>     <%= a.label(:importance_2, "kind of important") %>     <%= a.radio_button(:importance , 3) %>     <%= a.label(:importance_1, "a thing trade for")%> </ul> <ul>         <li id ='comments'>comments:          <%= a.text_field :comments %>        </li>  </ul>   <ul> <%end %> <div id = "qsubmit" > <%= f.submit %> </div>   <%end %> 

my controller looks .....

 def update  @formresults = params[:category]       @category = category.find(params[:id])      @formresults = params[:category]       @question_id = @formresults[:question_id]  @user_id = @formresults[:user_id]  @answer_details = @formresults[:answer]   @answer=@category.questions.find(@question_id).answers.find_by_user_id(@user_id)  @answer.agree = @answer_details[:agree]  @answer.importance = @answer_details[:importance]  @answer.importance = @answer_details[:comments]   if @answer.save          @counter = @question_id.to_i          @counter = @counter+1          @current_question_rec = @category.questions.find(@counter)          @current_question = @current_question_rec.question           @current_question_id = @counter          @answer = @category.questions.find(@current_question_id).answers.find_by_user_id(@user_id)    respond_to |format|      format.html { redirect_to @category }          format.js { render }  end  end end 

update.js.erb....

$('#questionarea').html( "<%= escape_javascript render :partial =>  "current_question" %> "); $('#hiddenparms').html( "<%= escape_javascript render :partial => "hiddenparms" %> "); 

not sure if has have nested resource has 1 record , form_for origintes possible increment question level in fields_for or should eliminate top level altogether , start forms_for @ question level create new method in categories controller handle gonna try , if works post answer

do have app/code on github? if share link, might matter.

i think found mistake, can please show models.

if @answer.save      @counter = @question_id.to_i      @counter = @counter+1 !here=> @current_question_rec = @category.questions.find(@counter)      @current_question = @current_question_rec.question       @current_question_id = @counter      @answer = @category.questions.find(@current_question_id).answers.find_by_user_id(@user_id)      respond_to |format|    format.html { redirect_to @category }        format.js { render }    end  end 

i updated - error is: => want skip next question, not passing in right parameters. now, have seen question.rb (model)

try:

!here=> @current_question_rec = @category.questions.find_by_question_id(@counter) 

it useful if host code on github (for free) , publish link here, might try application myself , find out answers.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -