ruby on rails: How do I access variable data in a url parameter passed to a model?

Posted by bandhunt on Stack Overflow See other posts from Stack Overflow or by bandhunt
Published on 2010-05-04T20:36:26Z Indexed on 2010/05/04 20:38 UTC
Read the original article Hit count: 272

Filed under:
|

I have a variable called "account_type" passed from a rails form and need to access the value in the corresponding model.

I can check if :account_type exists as a symbol, but where does the stored data come into play? Is there something I need to do in the controller?

This code gives an undefined method 'account_type' error.

validates_format_of :name, :with => /^[a-z0-9_]+$/i, :on => :create if account_type == 2 

If I use a symbol then it doesn't give an error, but a symbol will never equal 2

validates_format_of :name, :with => /^[a-z0-9_]+$/i, :on => :create if :account_type == 2

It's confusing that you can validate the format of a symbol (like :name above) when :name only seems to be a reference with nothing stored in it.

Thanks!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby