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 IDThe 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 "<p>" + item.description + "</p>" 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 Franco -- Posted via http://www.ruby-forum.com/.
Gama Franco
2006-Jul-04 23:13 UTC
[Rails] Re: Select Box problem in the controler with Ajax
Ok, I found the answer: if @params[:id].empty? render_text "<p/>" else item = Item.find(@params[:id]) render_text "<p>" + item.description + "</p>" end Gama Franco 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 "<p>" + item.description + "</p>" > 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 Franco-- Posted via http://www.ruby-forum.com/.