How best to do this? I have the following code: <%= collection_select(:country, :id, @country_list, :id, :country_name, options ={:prompt => "-- Select a country --"}, :class =>"country") %> How can I ensure that this the is validated correctly? I have tried validates_prescence_of, but does not seem to work when I select an actual country - it says: Country can''t be blank Any idea what this could mean or how should I do this? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 4 August 2010 15:37, disruptive tech <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> How best to do this? > > I have the following code: > > <%= collection_select(:country, :id, @country_list, :id, :country_name, > options ={:prompt => "-- Select a country --"}, :class =>"country") %> > > How can I ensure that this the is validated correctly? > > I have tried validates_prescence_of, but does not seem to work when I > select an actual country - it says: > > Country can''t be blank > > Any idea what this could mean or how should I do this?It means that you have said validates_presence_of country and it is blank, so is not present, so the validation fails. Look in development.log to see what values are being passed to the controller. If necessary use ruby-debug to break in to the controller at the save to see what you have put into the record being saved. See the Rails Guide on debugging if you do not know how to do this. Colin> -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Colin, The development log looks like its going to be useful in the future. This is what I get for the country: country"=>{"id"=>"6"}, so it looks like a value has been selected, but the validation still fails... Colin Law wrote:> On 4 August 2010 15:37, disruptive tech <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> select an actual country - it says: >> >> Country can''t be blank >> >> Any idea what this could mean or how should I do this? > > It means that you have said validates_presence_of country and it is > blank, so is not present, so the validation fails. Look in > development.log to see what values are being passed to the controller. > If necessary use ruby-debug to break in to the controller at the save > to see what you have put into the record being saved. See the Rails > Guide on debugging if you do not know how to do this. > > Colin-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
surely something seems amiss in the drop down control?? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Wed, Aug 4, 2010 at 8:51 AM, disruptive tech <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> surely something seems amiss in the drop down control??Why would you think that if you can see the country id being passed into the controller? Look at your controller code. Use ruby-debug as suggested, or add some debugging log statements. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder wrote:> On Wed, Aug 4, 2010 at 8:51 AM, disruptive tech <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: >> surely something seems amiss in the drop down control?? > > Why would you think that if you can see the country id being passed > into the controller? > > Look at your controller code. Use ruby-debug as suggested, or add > some debugging log statements. > > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassanis it formatted in the correct way? with the country"=>{"id"=>"6"}, should it be: country"=>"6"??? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Aug 5, 2010 at 3:13 AM, disruptive tech <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> is it formatted in the correct way?Most likely. You''ll know for sure if you follow the suggestions to debug your controller :-) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.