<%= link_to "开始游戏", {controller: "games", action: "start",id: @game.id},remote:true, :method => :get,"data-no-turbolink"=>true,class: "btn btn-primary btn-block ", id: "begin_button" %>
controller
def start
@game = Game.find(params[:id])
@game.start
respond_to do |format|
format.js { }
end
end
我发现如果我点了这个链接,之后每次刷新页面时都会自动执行 game start 这个动作 这是为何? 补充 game model
def start
self.pads.each_with_index do |pad,index|
ActionCable.server.broadcast "pad_channel_#{pad.room.true_number}",
{action: "game_start",role: pad.role, message: render_message(pad) }
end
self.update(begin_time:Time.new)
end