我有一個沒有主鍵的表格 - Player_ID,季節和金額。當我想更新我當前的表時我有這個錯誤消息:ActiveRecord :: StatementInvalid(Mysql2 ::錯誤:未知列'工資。'在'where子句'中:UPDATE salaries
SET Season
= 20192,Amount
= 3232.0 WHERE salaries
。 `IS NULL)update_attributes中的where子句導致Rails錯誤
更新方法在我的控制器:
def new
@salary = Salary.new
@players = Player.all
@title = "Add salary"
end
def create
@players = Player.all
@salary = Salary.new(params[:salary])
if @salary.save
flash[:success] = "Successfully added salary"
redirect_to salaries_path
else
@title = "Add salary"
render 'new'
end
end
def edit
@player_id = params[:player_id]
@season = params[:season]
@salary = Salary.find_by_Player_ID_and_Season(params[:player_id], params[:season])
@players = Player.all
@title = "Edit salary"
end
def update
@players = Player.all
@player_id = params[:player_id]
@season = params[:season]
@salary = Salary.find_by_Player_ID_and_Season(params[:player_id], params[:season])
if @salary.update_attributes(params[:salary])
flash[:success] = "Successfully edited salary"
redirect_to salaries_path
else
render 'edit'
end
end
_form.html.erb
<%= form_for(@salary, :url => salary_path(:player_id => @player_id, :season => @season)) do |f| %>
<%= f.collection_select :Player_ID, @players, :ID, :Name %>
<%= f.text_field :Season %>
<%= f.text_field :Amount %>
<%= f.submit "Add" %>
<% end %>
聽起來像是你的工資表沒有主鍵 –
是的。 A沒有主鍵。我有三列 - Player_ID,季節和金額。我想在數據庫中編輯一些行。這是我的目標。 – user1107922