У меня есть 3 объекта: пользователи, путешествия, очки.
У пользователя много поездок, у путешествия много точек, точка принадлежит одному путешествию и одному пользователю.
Путешествие также имеет логический атрибут (: open), который сообщает, проклято оно или нет.
Проблема в том, что я не могу сохранить "travel_id" текущего путешествия в моей таблице очков.
Вот код:
class Point < ActiveRecord::Base
belongs_to :travel, :foreign_key=> "travel_id"
belongs_to :user, :foreign_key=> "user_id"
end
class Travel < ActiveRecord::Base
has_one :user, :foreign_key => "user_id"
has_many :ways
has_many :points
attr_accessible :description, :start_date, :last_date
validates_date :last_date, :on_or_after => :start_date
end
Контроллер очков:
...
def create
@point = Point.new(params[:point])
@point.user_id = current_user.id
@travel = current_user.travels.find(:all, :conditions => {:open => true})
@point.travel_id = @travel.id
respond_to do |format|
if @point.save
format.html { redirect_to(@point, :notice => 'Point was successfully created.') }
format.xml { render :xml => @point, :status => :created, :location => @point }
else
format.html { render :action => "new" }
format.xml { render :xml => @point.errors, :status => :unprocessable_entity }
end
end
end
...
Каждый раз, когда я пытаюсь сохранить новую точку, @ point.travel_id = -614747648