目前正在尝试通过在视图中单击按钮来切换数据库中民意调查的 is_live 属性。这是表单并单击,它不会在参数中发送民意调查数据。
- current_user.polls.each do |poll|
%tr#poll.id
%td
/ Need to add (poll) as it needs the ID to match to the route.
=link_to "#{poll.title}", poll_path(poll)
%td
=link_to "Edit", edit_poll_path(poll)
%td
- if poll.is_live
= link_to "Stop"
/ , post, :method=>:toggle_live, :remote=>true, :class => 'btn btn-danger stop-poll'
- else
**= link_to "Start", polls_toggle_live_path(poll), :method => :post, :remote => true, :locals => poll, :class=> 'btn btn-success btn-small start-poll'**
PollsController 中指向此操作的链接
def toggle_live
binding.pry
@poll = Poll.find(params[:id])
respond_to do |format|
**format.js {@poll.toggle_live}**
end
end
哪个链接到 Poll 模型中的这个方法 我已经在 rails c 中测试过了,它确实切换了布尔值的切换
def toggle_live
if self.is_live
self.is_live = false
else
self.is_live = true
end
end
如何使用所有这些东西通过点击事件切换布尔值?
目前我从服务器日志中收到此错误:
Started POST "/polls/toggle_live.30" for 127.0.0.1 at 2013-06-09 12:15:02 -0400
Processing by PollsController#toggle_live as
Completed 404 Not Found in 2447731ms