Newb Newb wrote:
> Hi..
> i have a auto complete field for my authority_id field.authority_id
> field is not mandatory.if the user not fills it will take the default
> authority id as value.
> but i want to validate if the user enters invalid authority name into
> the auto complete text box...
> i can do this in my controller...
> but how can i implementd as modal validation.
> pls help on this
> below is my controller side implementation
>  #if autority text box is empty?
>  if params[:user_info][:login].empty?
>               @user = UserInfo.find_by_login('admin')
>               @company.authority_id = @user.id
>  else
>      authority = UserInfo.find_by_login(params[:user_info][:login])
>      if authority.nil?
>         flash[ :error ] = "*Please Enter valid Authority name"
>      else
>          @company.authority_id = authority.id
>      end
>  end


Hi newb!

There's a validation called validates_associated which checks if an 
assosciated object is also valid.

So in company, you could add

validates_associated :authority :unless => lambda { |comp| 
comp.authority_id.nil? }

This will check if the associated authority is a valid one provided the 
company's authority_id is not nil



-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to