Raoot
Raoot

Reputation: 1771

Rails 3.1 - Conditional statements in a model?

Is it possible to use conditional statements in a Rails Model?

I'm thinking something like this:

if create
  before_save do
  self.position = self.track.position
  end
else
  acts_as_list :scope => :product_id
end

I basically want acts_as_list to be effective after the initial create has been done.

Upvotes: 0

Views: 111

Answers (1)

Veraticus
Veraticus

Reputation: 16064

It looks like you're looking for before_create.

class Model < ActiveRecord::Base

  acts_as_list :scope => :product_id
  before_create :set_initial_position

  private

  def set_initial_position
    self.position = self.track.position
  end
end

Upvotes: 3

Related Questions