我有一个没有主键的表,包含三列 - Player_ID、Season 和 Amount。当我想更新当前表时,出现以下错误消息:ActiveRecord::StatementInvalid (Mysql2::Error: Unknown column 'salaries.' in 'where clause': UPDATE salaries
SET Season
= 20192, Amount
= 3232.0 WHERE salaries
.`` IS NULL)
我的控制器中的更新方法:
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 %>