Glen Holcomb
6/30/2008 9:10:00 PM
[Note: parts of this message were removed to make it a legal post.]
On Mon, Jun 30, 2008 at 2:38 PM, Todd Benson <caduceass@gmail.com> wrote:
> On Mon, Jun 30, 2008 at 12:10 PM, brian <brian@arielpremium.com> wrote:
> > Maybe it will be clearer if I will just begin with the symptom.
> >
> > I am getting an error saying "Couldn't find Itemprice without an ID"
> >
> > This message comes up even despite the fact that this is my controller:
> >
> > class ItempriceController < ApplicationController
> > def show
> > @itemprices = Itemprice.find(params[:ItemSerial])
> > end
> > end
> >
> >
> > I am not finding Itemprice by id according to the above, but still I get
> > this error.
> >
> > In my view as a test I have the following:
> >
> > <% @page_title = "#{@itemprices.Price1}" %>
> >
> > -Brian
>
> Hmm. I'm no Rails expert, but maybe you should check the type/class
> of the object params[:ItemSerial]. Just a thought. Also, your
> database setup may be strange for Rails as I alluded to earlier. I've
> actually had this error a few times before, but can't remember how I
> fixed it :/
>
> Todd
>
>
It sounds to me like Itemprice.find(params[:ItemSerial]) is returning nil
for whatever reason. This is getting passed along and then rails is trying
to retrieve the item from the database using nil for the id in your view.
If you are doing a find with one argument rails assumes that argument
evaluates to an id value. If you want to match on a field you would need
something like find(:all, :conditions => ["serial = ?",
params[:ItemSerial]])
--
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."
-Greg Graffin (Bad Religion)