Validates_inclusion_of Rails 3 with a request that does not work properly

I am new to Rails and I ran into a problem. I have

Models

Model1
id: integer
account_id: integer

Account
id: integer

I have a check in Model1 as follows:

Model Code:

validates :account_id, :inclusion => { :in => Account.find(:all).collect(&:id)}

I use the drop-down menu for View code:

<%= f.select :account_id, @accounts.collect {|acc| [acc.name, acc.id]}, {:prompt => 'Select Account' }, { :selected => @defaultaccount, :class => 'selectwidth' } %>

I use client-side validation to validate the fields before submitting the form. I use Heroku to deploy my application.

, , 1. , . , , "", validates_inclusion_of, . , , , .

validates_inclusion_of rails 3 validates: account_id,: include = > {: in = > {}} . model1. .

, 1 , .

, ? ? , , , , .

, , , , , . ? , .

Config, 3 Asset

: Kaminari

+3
2

, , :in => Account.find(:all).collect(&:id) , Rails . , . , , .

+2

( ). , , .

1.8.7 :

validates :account_id, :inclusion => { :in => lambda {Account.find(:all).collect(&:id)}}

1.9.2 :

validates :account_id, :inclusion => { :in => ->{Account.find(:all).collect(&:id)]}
+1

All Articles