So I have some data that gets pulled from another rails app in a controller lets call it ExampleController and I want to validate it as being there in my model before allowi
The only way to share controller level data with model is through external accessor. Using metaprogramming you can trick the way to pass it to a model instance.
def valid_data?
data = #data could be nil or not
result = data.blank? ? false : true
instance_eval <<-EOV
def AWizard.new(*args)
super(*args).tap {|aw| aw.external_valid = #{result}}
end
EOV
result
end
class AWizard
attr_accessor :external_valid
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
validate :first_step_data, :if => lambda { |o| o.current_step == "step1" };
def first_step_data
# :external_valid would be true or false according to a valid_data?. Nil would be if valid_data? has not been called
if external_valid == false
errors.add ...
end
end
end