Empty parameter submitted but .nil failed to detect it

hi guys

i have a form which has an element, “category id”.

When i submit it with values, i can see param(:category) with a value
(as i print out that value in the controller’s method.

Anyway, when i submit my form without selecting any category, the
method in the controller does not pick up on it.
I tried using .nil? but it doesn’t work.

This is my code:
def get_subcategories
if params[:category]
puts " I M in GET SUBCATEGORIES -" + params[:category] +
‘…’
@category = Category.find(params[:category])
@sub_categories = @category.sub_categories.all
else
puts “no given category id to retrieve the subcategory”
end
end

When i run the application and submit without a category value , i
notice that params[:category]
is still defined (hence printing out “I M in GET SUBCATEGORIES”) when
it should not be.
I have even tried “params[:category].nil?”

Any ideas? In perl, i could test the variable for truth (IE if
($params->{‘category’}) then …

2009/10/13 ct9a [email protected]:

 I tried using .nil? but it doesn’t work.
    end
  end

When i run the application and submit without a category value , i
notice that params[:category]
is still defined (hence printing out “I M in GET SUBCATEGORIES”) when
it should not be.
I have even tried “params[:category].nil?”

Would .blank? do what you want?

Colin

On Tue, Oct 13, 2009 at 8:11 AM, Colin L. [email protected]
wrote:

Anyway, when i submit my form without selecting any category, the
else

Would .blank? do what you want?

Colin

Colin’s right - I would code: if not params[:category].blank?


www.abetaday.com

Hi friend,

U can try this,

if params[:catergory] != nil