Forum: Ruby on Rails If Param not set...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
08579165083bc2901c02d2617bffc84f?d=identicon&s=25 Justin Johnson (Guest)
on 2006-01-25 14:41
Hello all, I'm developing an application which allows users to browse
items for sale...

Using the url localhost:3000/browse/by_type/2    (2 is the id of the
category they are in)

Displays the information I want, however localhost:3000/browse/by_type/
will display an error page (becuase the id param is not set)

in my by_type.rhtml view, how to i check to see if the param is set? and
if not display a message?


Also similar question: I have a Property model where I use
@properties = find(:all, :condition["type_id = ?", @param['id']])

How do I display a "no items found message" if @properties is empty (ie:
no products for that category)

Thanks!
317aad7f9f0b69a440faca74bbe22b20?d=identicon&s=25 Jakob Skjerning (Guest)
on 2006-01-25 15:10
(Received via mailing list)
Justin Johnson wrote:
> in my by_type.rhtml view, how to i check to see if the param is set? and
> if not display a message?

<% if params[:id].nil? %>
   Message
<% end %>

> Also similar question: I have a Property model where I use
> @properties = find(:all, :condition["type_id = ?", @param['id']])
>
> How do I display a "no items found message" if @properties is empty (ie:
> no products for that category)

<% if @properties.empty? %>
   Yes, it really is this easy
<% end %>
This topic is locked and can not be replied to.