0
如何保存屬性..我有一個非常簡單的問題..這裏我嘗試保存屬性的新對象像在因爲即時通訊新軌軌
@receiver = User.find_by_email(params[:email])
@sender = User.find_by_email(current_user.email)
logger.info "@receiver.inspect"[email protected]
logger.info "@sender.inspect"[email protected]
@newConnection = Connection.new
@newConnection.user1 = @receiver.id
@newConnection.user2 = @sender.id
if @newConnection.save
flash[:message] = "Saved Succesfully!"
,但它的作用只是保存的默認領域,而不是接收者和發送者ID爲日誌
INSERT INTO `connections` (`created_at`, `updated_at`) VALUES ('2015-06-30 20:14:30', '2015-06-30 20:14:30')
我的連接模型就像
class Connection < ActiveRecord::Base
attr_accessor :user1,:user2
belongs_to :user1, :class_name => "User"
belongs_to :user2, :class_name => "User"
end
模型M移徙
class CreateConnections < ActiveRecord::Migration
def change
create_table :connections do |t|
t.integer :user1_id, :references => [:users, :id]
t.integer :user2_id, :references => [:users, :id]
t.date :connectedOn
t.string :currentStatus
t.timestamps
end
end
end
請幫忙!
向您的連接控制器顯示強參數的定義。 – uday