Hassan,

I accidentally cause my reply to fire before I complete my statement.
Here's the continuation:

> My problem was that even though my approach failed with Rails
> displaying the params as I described the,  the crash was in am
> instance of an Expense model,  so I
I tried to get the ID of the Vendor instance referenced in the form
using the params hash.  But that hash wasn't accessible to the model
instance.  Hence the crash.

Pursuant to a previous reply to my posted question, I learned that I
could get the select-vendor's id with vendor_id in the
validate_on_create method of the Expense class instance and thus cause
an error message to be generated at the top of the form in the
browser.  Testing shows that all this works fine.

So what do I fail to understand.  (A lot, no doubt, but how much about
my validation of vendor selection on this form.)

Best wishes,
Richard

On Aug 10, 3:30 pm, RichardOnRails
<[email protected]> wrote:
> Hi Hassan,
>
> > > I've code exactly the logic I wanted, except for how to enforce that a
> > > vendor be selected from the drop-down before creating a new expense
> > > record.
>
> > Which you cannot do. You can "know" absolutely nothing about what
> > happens on the client side; all you can do is handle the requests that
> > you receive. Which may not include parameters that you're hoping to
> > see :-)
>
> I don't mean to be obstinate, Hassan.  The problem is I don't see
> what's wrong with what my code presently does:
>
> My perception is that my browser renders a form with a drop-down for
> vendor selection.  That drop-down is populate via a
> f.collection_select second parameter,  vendors_for_exp (with no
> argument).
>
> The latter is a method defined in app\helpers\expenses_helper.rb as
> follows:
>   def vendors_for_exp(add_null_item = true)
>     v = Vendor.find( :all, :order=>"nickname ASC")
>     if add_null_item
>       v0=Vendor.new; v0.id=0; v0.nickname = "--Select Vendor--"
>       v.insert(0, v0)
>     end
>     v
>   end
>
> The values of all the fields are are stored in params[:expenses] as a
> hash.  In particular, the vendor instance selected by the user is
> stored in  params[:expenses][:vendor].  In particular,  the id of that
> Vendor instance is accessible as params[:expenses][:vendor][:id].
> (I think strings or used instead of symbols for this stuff, but let's
> ignore that.)
>
> My problem was that even though my approach failed with Rails
> displaying the params as I described the,  the crash was in am
> instance of an Expense model,  so I
>
> On Aug 9, 11:18 am, Hassan Schroeder <[email protected]>
> wrote:
>
> > On Mon, Aug 9, 2010 at 8:08 AM, RichardOnRails
>
> > <[email protected]> wrote:
> > >> I'd suggest that it's good practice to handle any (even nil) input value
> > >> in a way appropriate to your business logic.
>
> > > I've code exactly the logic I wanted, except for how to enforce that a
> > > vendor be selected from the drop-down before creating a new expense
> > > record.
>
> > Which you cannot do. You can "know" absolutely nothing about what
> > happens on the client side; all you can do is handle the requests that
> > you receive. Which may not include parameters that you're hoping to
> > see :-)
>
> > Hence my suggestion that your code deal appropriately with those
> > situations, however unlikely you might think they are.
>
> > Good luck,
> > --
> > Hassan Schroeder ------------------------ [email protected]
> > 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 [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