How to use two attributes in one validates_inclusion_of statement?

Hey hey :slight_smile:

Might be a dumb-ass question, but then please bear with me.

I'm trying to add these two validations to a model:

  validates_inclusion_of(:controller, :in => controllers, :message => 'does not exist in this application')   validates_inclusion_of(:action, :in => controllers[:action], :message => 'is not implemented in the specified controller')

Basically, controllers is a method that creates a hash of all controllers in my application, and an array of method names for each hash entry. The method works fine, and queries work like I would expect, e.g.,   c = controllers => {"store"=>["index", "list", "search", "show"], "a......   c.include? 'store' => true   c['store'].include? 'index' => true

The first validates_inclusion_of works fine. But I don't know how to get the second validates_inclusion_of to use the value of the action attribute on the object in question. I've tried :action, action, @action, and @@action, but none of them contain the value of the action attribute on the object that I'm working on. How can I get to that attribute and use it in my validation statement above?

Thank you very much for any help :slight_smile:

Daniel

Could try params[:action] though I’m not sure if that’s available to you at that time.

Jason

Jason Roelofs wrote:

Could try params[:action] though I'm not sure if that's available to you at that time.

Jason

Not really, as it's on the model level. Thanks, though :slight_smile:

self.bonk!

Yeah, missed that. This might just need to be controller-side validation. In terms of MVC architecture, the model should know nothing about the state of the controller.

Jason

Jason Roelofs wrote:

self.bonk!

LOL :slight_smile:

Yeah, missed that. This might just need to be controller-side validation. In terms of MVC architecture, the model should know nothing about the state of the controller.

Yes, but it is not in the controller - both attributes are on the model. I want to check that the :controller value indeed matches an existing controller, and then, that the :action matches an action implemented in this controller. But to do the latter (the former works fine right now), I need to check my self-created controller hash at the correct index - like this,

validates_inclusion_of(:action, :in => controllers[:controller], :message => 'is not implemented in the specified controller')

Except that I don't know how to get the value in the :controller attribute. Nothing I can think of writing yields that value... Do I make any sense? Here's the entire model:

# == Schema Information # Schema version: 6