2 つのモデルがUser
ありMotor
、各テーブルにはname
列があります。ユーザーが持っているすべてのモーターを表示するユーザーページがあります。
私がやった方法はname
、テーブルの列がテーブルの列Motor
と等しくなるようにすることでしたname
User
Motor User
name1 name1
name3 name2
name1 name3
name1 name4
name4 name5
のページを見ると、 という名前name1
の のすべてのレコードが表示されます。Motor
name1
しかし、テーブル内の名前を更新したい場合、User
テーブル内のすべてのレコードを変更するにはどうすればMotor
よいuser
ですか?
name1
like に変更した場合last1
、すべてname1
の をlast1
tableMotor
に変更するにはどうすればよいですか?
これは私のコントローラーshow
メソッドです
def show
@user = User.find(params[:id])
@motor = Motor.where(:name => @user.name)
end
update
次に、方法を変更する必要があると想定しています
if @user.update_attributes(params[:user])
if params[:name]
# whats the correct way of changing all records that was previously the same name as user in the motor table?
end
end
ありがとう