0
我可以創建一個遊戲,在那個遊戲中我可以創建規則,我有一個 按鈕,「完成」規則,通過更改規則布爾值 :completed column假,它推到「規則完成」 視圖,我有一個按鈕,「更新」規則,通過更改規則 布爾:已完成列回真。在Ruby的單獨表格中創建動作的分數
所以,我的下一個任務是創建新的得分控制器創建方法:
- 通過相同的「已完成」 button_to行動,
- 查找與button_to的規則,並插入該規則ID到列「rule_id」中新的 表,Score。
- 還張貼完成(時間用戶點擊 按鈕)的分數表中,列「complete_time」的時候,
我曾嘗試是簡單地複製大部分的細節
def create
@rule = @game.rules.new(params[:rule])
if @rule.save
flash[:notice] = "You have added a Rule to your Game!"
redirect_to game_url(@game)
else
flash[:error] = "We couldn't add your Rule."
redirect_to game_url(@game)
end
end
我在重複這對RULE_ID張貼到積分表格最新努力,列「RULE_ID」如下:
def create
@rule = Rule.find(params[:id])
@score = @rule.scores.new(params[:rule_id])
if @score.save
flash[:notice] = "You scored!"
redirect_to game_url(@game)
else
flash[:error] = "Wide right, try again."
redirect_to game_url(@game)
end
end
0123在規則控制器,它是創造 方法
我的新成績db是:
class CreateScores < ActiveRecord::Migration
def change
create_table :scores do |t|
t.integer :rule_id
t.datetime :completed_time
t.timestamps
end
end
end
我所提出的分數按鈕操作是:
<%= button_to "Score!", score_path(@game.id,rule.id) %>
和路線設置爲:
Tgom::Application.routes.draw do
resources :games do
resources :rules do
resources :scores do
end
end
end
match 'games/:game_id/rules/:id/complete' => 'rules#complete', :as => :complete_rule
match 'games/:game_id/rules/:rule_id/scores' => 'scores#create', :as => :score
match 'games/:game_id/rules/:id/uncomplete' => 'rules#uncomplete', :as => :uncomplete_rule
root :to => 'games#index'
該設置的電流誤差閱讀:
ActiveRecord::RecordNotFound in ScoresController#create
Couldn't find Rule without an ID
Rails.root: c:/Sites/tgom
app/controllers/scores_controller.rb:9:in `create'