1
현재보기에서 버튼을 클릭하여 데이터베이스의 폴링 is_live 속성을 전환하려고합니다. polls 데이터를 params로 보내지 않는 폼과 클릭이 있습니다. PollsController에서이 작업에 대한 링크AJAX를 사용하여 데이터베이스의 부울 열을 전환하는 방법?
- 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'**
내가 레일 C에서 이것을 테스트했습니다 폴링 모델에서이 방법으로 연결하고 토글 스위치 않습니다
def toggle_live
binding.pry
@poll = Poll.find(params[:id])
respond_to do |format|
**format.js {@poll.toggle_live}**
end
end
부울 값
def toggle_live
if self.is_live
self.is_live = false
else
self.is_live = true
end
end
이러한 모든 것을 어떻게 사용할 수 있습니까? 클릭 이벤트로 부울을 전환 하시겠습니까?
는 현재 내가 서버 로그에서이 오류를 받고 있어요 : 404에 대한
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