Player_ID、Season、Amount の 3 つの列を持つ主キーのないテーブルがあります。現在のテーブルを更新しようとすると、次のエラー メッセージが表示されます: 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 %>