Select Box problem in the controler with Ajax

Hi,

I have a selectbox that updates a given span area when a user selects a
value. The selectbox has the option :include_blank => true. The
controler will fetch the ID of the selected option in the combo box and
sends the description of the item with the same ID.

The problem is that the user is able to select the empty option, and the
controler will not be able to fecth the ID. This provides the error:
Couldn’t find Item with ID=
The id is blank, and this is why it shows the message.

The code of the controler is:

def display_item_description
item = Item.find(@params[:id])
render_text “

” + item.description + “


end

I know I need to perform some kind of check on the @params[:id], but I
don’t know how to do it.

Thanks in advance,
Gama F.

Ok, I found the answer:

if @params[:id].empty?
render_text “


else
item = Item.find(@params[:id])
render_text “

” + item.description + “


end

Gama F. wrote:

Hi,

I have a selectbox that updates a given span area when a user selects a
value. The selectbox has the option :include_blank => true. The
controler will fetch the ID of the selected option in the combo box and
sends the description of the item with the same ID.

The problem is that the user is able to select the empty option, and the
controler will not be able to fecth the ID. This provides the error:
Couldn’t find Item with ID=
The id is blank, and this is why it shows the message.

The code of the controler is:

def display_item_description
item = Item.find(@params[:id])
render_text “

” + item.description + “


end

I know I need to perform some kind of check on the @params[:id], but I
don’t know how to do it.

Thanks in advance,
Gama F.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs