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