0
我必須爲桌面遊戲中的p1條目做一個增加值按鈕「bg」,但它不工作...它用p1 = 0保存遊戲但link_to沒有效果。Rails動態增加按鈕
非常感謝您的幫助! (和我的英語不好對不起......)
控制器
def create
@game = Game.new(params[:game])
@game.p1 = 0
respond_to do |format|
if @game.save
format.html { render action: "show" }
end
end
end
def show
@game = Game.find(params[:id])
respond_to do |format|
format.js {render 'hnew'}
end
end
def add_three_points
@game = Game.find(params[:id])
@game.update_attribute(:p1, @game.p1 + 3)
end
意見
show.html.erb
<%= render 'hnew' %>
hnew.js.erb
$('#ajax_hidden').html("<%= escape_javascript(render('hnew')) %>");
_hnew.html.erb
<%= link_to "bg", add_three_points_path(@game.id), {remote: true, method: :put},
class: 'btn btn-small' %>
<%= @game.p1 %>
錯誤消息:
Started PUT "/add_three_points.14" for 127.0.0.1 at 2013-07-10 21:27:01 +0200
Processing by GamesController#add_three_points as
Completed 404 Not Found in 1ms
ActiveRecord::RecordNotFound (Couldn't find Game without an ID):
app/controllers/games_controller.rb:86:in `add_three_points'
只要嘗試,但仍然沒有效果點擊按鈕:( – druido82