Hi.. I have a select which I want to validate if a value is selected, otherwise not. <%= f.collection_select :parent_id, Project.mainprojects.active, :id, :project_name, :include_blank => ''Partproject?'', :allow_nil => true%> how is the correct way..? tried..in model if :project_id if :project_id? if :project_id.blank? etc . etc. But nothing works.. -- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/XXs2J-r5udIJ. For more options, visit https://groups.google.com/groups/opt_out.
On Wed, Oct 24, 2012 at 3:01 PM, Werner <webagentur.laude-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>wrote:> Hi.. > I have a select which I want to validate if a value is selected, otherwise > not. > > <%= f.collection_select :parent_id, Project.mainprojects.active, :id, > :project_name, :include_blank => ''Partproject?'', :allow_nil => true%> > >so the name of the input is SOMETHING[parent_id] right? then you have to validate if self.parent_id.blank? Javier -- 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 https://groups.google.com/groups/opt_out.
On 24 October 2012 21:01, Werner <webagentur.laude-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hi.. > I have a select which I want to validate if a value is selected, otherwise > not. > > <%= f.collection_select :parent_id, Project.mainprojects.active, :id, > :project_name, :include_blank => ''Partproject?'', :allow_nil => true%> > > how is the correct way..? > > tried..in model > if :project_id > if :project_id? > if :project_id.blank? > > > etc . etc. > But nothing works..So what is the value of project_id that you are trying to test for? If you are not sure then have a look at the Rails Guide on debugging which will show you techniques that you can use to debug your code. Then you can find out what is the value of project_id and why your tests are not working. Colin -- 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 https://groups.google.com/groups/opt_out.
Am 24.10.2012 um 22:32 schrieb Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: Hi Colin.. <%= f.collection_select :parent_id, Project.mainprojects.active, :id, :project_name, :include_blank => ''Partproject?'', :allow_nil => true%> the project_id .. 1, 2 etc. or "" "parent_id"=>"1" "parent_id"=>"" Werner> On 24 October 2012 21:01, Werner <webagentur.laude-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> Hi.. >> I have a select which I want to validate if a value is selected, otherwise >> not. >> >> <%= f.collection_select :parent_id, Project.mainprojects.active, :id, >> :project_name, :include_blank => ''Partproject?'', :allow_nil => true%> >> >> how is the correct way..? >> >> tried..in model >> if :project_id >> if :project_id? >> if :project_id.blank? >> >> >> etc . etc. >> But nothing works.. > > So what is the value of project_id that you are trying to test for? > If you are not sure then have a look at the Rails Guide on debugging > which will show you techniques that you can use to debug your code. > Then you can find out what is the value of project_id and why your > tests are not working. > > Colin > > -- > 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 https://groups.google.com/groups/opt_out. > >Werner Laude webagentur.laude-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org -- 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 https://groups.google.com/groups/opt_out.
On 24 October 2012 22:01, Werner Laude <webagentur.laude-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > Am 24.10.2012 um 22:32 schrieb Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > > Hi Colin..Please don''t top post, it makes it difficult to follow the thread. Insert your reply at appropriate points in previous message. Thanks.> > <%= f.collection_select :parent_id, Project.mainprojects.active, :id, :project_name, :include_blank => ''Partproject?'', :allow_nil => true%> > > the project_id .. 1, 2 etc. or "" > > "parent_id"=>"1" > "parent_id"=>""You said in your initial post that you were testing it in the model. What do you mean by "parent_id" => ""? In the model it should probably be an attribute self.parent_id, but in that case I would expect it to be nil if it is a foreign key. If you are trying to test it in the controller then it depends what you are trying to do. Show us the code you have tried (for the action, not just one line out of context). Colin> > Werner > > > >> On 24 October 2012 21:01, Werner <webagentur.laude-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>> Hi.. >>> I have a select which I want to validate if a value is selected, otherwise >>> not. >>> >>> <%= f.collection_select :parent_id, Project.mainprojects.active, :id, >>> :project_name, :include_blank => ''Partproject?'', :allow_nil => true%> >>> >>> how is the correct way..? >>> >>> tried..in model >>> if :project_id >>> if :project_id? >>> if :project_id.blank? >>> >>> >>> etc . etc. >>> But nothing works.. >> >> So what is the value of project_id that you are trying to test for? >> If you are not sure then have a look at the Rails Guide on debugging >> which will show you techniques that you can use to debug your code. >> Then you can find out what is the value of project_id and why your >> tests are not working. >> >> Colin >> >> -- >> 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 https://groups.google.com/groups/opt_out. >> >> > > Werner Laude > webagentur.laude-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > > > -- > 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 https://groups.google.com/groups/opt_out. > >-- 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 https://groups.google.com/groups/opt_out.