0

当我更改应用程序的内容状态时,数据库更新的背景工作正常。但该link_to :loading操作不起作用。

查看:页面中元素的 _feedback_question_status.html.erb

<% if feedback_question.status == 1 %>
    <span id="feedback_question">enabled -- <%= link_to "change", {:action=>"feedback_question_status",:status => 0,:feedback_question=>feedback_question.id}, :remote=>true, :loading => "$('#feedback_question_disable_#{feedback_question.id}').replaceWith('<p>Loading..</p>')", :update =>"feedback_question"%></span>
<% else %>
    <span id="feedback_question">disabled -- <%= link_to "change",{:action=>"feedback_question_status",:status => 1, :feedback_question=>feedback_question.id }, :remote=>true, :loading => "$('#feedback_question_enable_#{feedback_question.id}').replaceWith('<p>Loading..</p>')", :update =>"feedback_question"%></span>
<% end %>

控制器:

update_attributesrender :partial=>'feedback_question_status'

在服务器上:

Started GET "feedback/feedback_question_status?feedback_question=6&status=1" for 127.0.0.1 at 2012-08-27 16:25:47 +0530
... Snippet
   (0.2ms)  BEGIN
...
   (30.7ms)  COMMIT
  Rendered _feedback_question_status.html.erb (2.7ms)

最后一行显示部分已渲染。但意见没有变化。这意味着页面上的元素没有任何反应。

为feedback_question 搜索路由:

  feedback_feedback_question_status        /feedback/feedback_question_status(.:format)                       feedback#feedback_question_status
                 feedback_questions        feedback/new_feedback_question(.:format)                          feedback#new_feedback_question
             edit_feedback_question        /feedback/:id/edit_feedback_question(.:format)                     feedback#edit_feedback_question
           update_feedback_question        /update_feedback_question/:id(.:format)                            feedback#update_feedback_question
           feedback_question_status        /feedback_question_status(.:format)                                feedback#feedback_question_status

刷新页面后显示更改。但我不想再次加载页面。

4

2 回答 2

0

您没有将局部变量“feedback_question”从控制器传递到部分文件 _feedback_question_status.html.erb。

所以你需要像下面一样传递局部变量“feedback_question”

渲染 :partial => "feedback_question_status", :localts => { :feedback_question => @feedback_question }

其中@feedback_question 是需要在控制器中创建的实例变量。

于 2012-08-27T11:55:46.243 回答
0

请更换这个

<% if feedback_question.status == 1 %>
  <span id="feedback_question">enabled -- <%= link_to "change", {:action=>"feedback_question_status",:status => 0,:feedback_question=>feedback_question.id}, :remote=>true, :loading => "$('#feedback_question_disable_#{feedback_question.id}').replaceWith('<p>Loading..</p>')", :update =>"feedback_question"%></span>
<% else %>
  <span id="feedback_question">disabled -- <%= link_to "change",{:action=>"feedback_question_status",:status => 1, :feedback_question=>feedback_question.id }, :remote=>true, :loading => "$('#feedback_question_enable_#{feedback_question.id}').replaceWith('<p>Loading..</p>')", :update =>"feedback_question"%></span>
<% end %>

这样

<span id="feedback_question"><%= feedback_question.status == 1 ? "enabled" : "disabled" %> -- <%= link_to "change", {:action=>"feedback_question_status",:status => (feedback_question.status == 1 ? 0 : 1),:feedback_question=>feedback_question.id}, :remote=>true, :loading => "$('#feedback_question_disable_#{feedback_question.id}').replaceWith('<p>Loading..</p>')", :update =>"feedback_question"%></span>

不要重复你的代码。

于 2012-08-27T12:48:37.803 回答