How do I check if error_messages_for is set? -- Posted via http://www.ruby-forum.com/.
On Aug 17, 7:31 pm, Pål Bergström <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> How do I check if error_messages_for is set?error_messages_for is a method, I assume what you meant to ask was how to check whether there are any errors. You can either call valid? or look at your_ar_object.errors Fred> -- > Posted viahttp://www.ruby-forum.com/.
Frederick Cheung wrote: Hmm. Ok. How do I check if a params part of the model is set? If run: if params[:kind] it''s ok. But when I test with if params[:company][:kind] it returns "The error occurred while evaluating nil.[]" -- Posted via http://www.ruby-forum.com/.
2009/8/17 Pål Bergström <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Hmm. Ok. How do I check if a params part of the model is set? If run: > > if params[:kind] > > it''s ok. But when I test with > > if params[:company][:kind] > > it returns "The error occurred while evaluating nil.[]"Look at the error carefully, if it is finding nil.[] then maybe either params is nil (unlikely unless you typed it incorrectly) or params[:company] is nil. Look in the log file (in your application log folder) it will show you the parameters posted. Colin
On Aug 17, 9:04 pm, Pål Bergström <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Frederick Cheung wrote: > > Hmm. Ok. How do I check if a params part of the model is set? If run: > > if params[:kind]That doesn''t check the model at all, you''re just looking at the submitted parameters. Or am I misunderstanding the question> > it''s ok. But when I test with > > if params[:company][:kind] > > it returns "The error occurred while evaluating nil.[]"if the parameters may or may not be there you need to check whether params[:company] exists before you can look at params[:company][:kind] Fred> -- > Posted viahttp://www.ruby-forum.com/.
Frederick Cheung wrote:> On Aug 17, 9:04�pm, P�l Bergstr�m <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote:> That doesn''t check the model at all, you''re just looking at the > submitted parameters. Or am I misunderstanding the questionIt''s a submitted parameters. :-)> if the parameters may or may not be there you need to check whether > params[:company] exists before you can look at params[:company][:kind]Thanks. That might be it. -- Posted via http://www.ruby-forum.com/.