我正在尝试在我的页面上呈现部分内容控制台或终端日志中没有错误,场景是......用户选择页面上的链接并且中间区域应该呈现。我正在通过 jquery 运行此程序,并让提交转到我的控制器“会话”和“showsurvey”方法,它获取必要的信息,然后呈现给 showsurvey.js.erb 以用 showsurvey 部分替换 html
这是涉及的代码....shownewuser.html.erb
<%= include_gon %>
<div id="content" class="clearfix">
<%= render :partial => 'layouts/user_profile' %>
<div class="inner">
<div class="top_area">
</div> <!-- top_area -->
<p>Welcome <%=@user.email%> Drag the topics into the order of importance to you.</p>
<div id="middle_area" >
<%= render :partial => 'middle_newuser' %>
<div id="find">
<p>Where voters and politicians can discuss and learn about the issues for free with no advertising dollars getting in the way <br />
Subscribe to RSS feeds to stay in touch with their latest votes. </p>
</div>
</div> <!-- inner_area -->
替换 _middle_newuser.html.erb 的原始部分
<div id = "draggable" class="ui-widget-content">
<h3 class="ui-widget-header">Issues</h3>
<table>
<tr><td>
<ul id ="column1" >
<% (0..5).each do |i| %>
<% @sm_pic= @cat[i][:small_pic]
@CatName = @cat[i][:name]
@id = @cat[i][:id]%>
<li id="draggable">
<%= link_to image_tag(@sm_pic, :border => 0), showsurvey_path({:data => @id}), :remote => true, :data => @id , :id => 'showSurvey' %>
</li>
<% end %>
</ul>
</td>
<td>
<ul id ="column1" >
<% (6..11).each do |i| %>
<% @sm_pic= @cat[i][:small_pic]
@CatName = @cat[i][:name]
@id = @cat[i][:id]%>
<li id="draggable">
<%= link_to image_tag(@sm_pic, :border => 0), showsurvey_path, :data => @id %>
</li>
<% end %>
</ul>
</td>
<td>
<ul id ="column1" >
<% (12..17).each do |i| %>
<% @sm_pic= @cat[i][:small_pic]
@CatName = @cat[i][:name]
@id = @cat[i][:id]%>
<li id="draggable">
<%= link_to image_tag(@sm_pic, :border => 0), showsurvey_path, :data => @id %>
</li>
<% end %>
</ul>
</td></tr>
</table>
</div id> <!-- draggable -->
</div> <!-- middle_area -->
以及应该替换这个 ...._middle_survey.html.erb 的部分
<div>
<table><tr>
<div id="middle_area-left" >
<p>Welcome this will be the survey page for user after clicking on a priority icon.</p>
</div>
<div id="middle_area-center" >
<%= render :partial => 'form' %>
</div>
<div id="middle_area-right" >
<p>Welcome this will be the survey page for user after clicking on a priority icon.</p>
</div>
</tr>
</table>
</div>
控制器方法是 showSurvey
def showsurvey
@title = "Survey for"
@category = Category.find(params[:data])
@questions = @category.questions.find_all_by_category_id(params[:data])
@current_question_rec = @questions.first
@current_question = @current_question_rec.question
@current_question_id = @current_question_rec.question_id
@answer = @category.questions.find(@current_question_id).answers.find_by_user_id(params[:id])
respond_to do |format|
format.html { redirect_to @category }
format.js { render }
end
end
最后一个 showSurvey.js.erb
$(#middle_area').replace_html( "<%= escape_javascript render :partial => "middle_survey" %> ");
还有一件事是我的终端的输出
Processing by SessionsController#showsurvey as JS
Parameters: {"id"=>"3", "data"=>"3"}
Category Load (0.2ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" = ? LIMIT 1 [["id", "3"]]
Question Load (0.4ms) SELECT "questions".* FROM "questions" WHERE "questions"."category_id" = 3 AND "questions"."category_id" = '3'
Question Load (0.3ms) SELECT "questions".* FROM "questions" WHERE "questions"."category_id" = 3 AND "questions"."question_id" = ? LIMIT 1 [["question_id", 1]]
Answer Load (0.3ms) SELECT "answers".* FROM "answers" WHERE "answers"."question_id" = 1 AND "answers"."user_id" = 3 LIMIT 1
Rendered sessions/_form.html.erb (4.1ms)
Rendered sessions/_middle_survey.html.erb (5.8ms)
Rendered sessions/showsurvey.html.erb (7.6ms)
Completed 200 OK in 26ms (Views: 13.9ms | ActiveRecord: 1.1ms)
感谢您的帮助