Redirect to city_path if @city.name not equal nil and ""
If @city.name equal "" also redirect to city_path. How to fix it?
if (@city.name != nil || @city.name != "")
redirect_to city_path
else
render 'index'
end
Redirect to city_path if @city.name not equal nil and ""
If @city.name equal "" also redirect to city_path. How to fix it?
if (@city.name != nil || @city.name != "")
redirect_to city_path
else
render 'index'
end
In one line with ternary operator
and blank?
method:
@city.name.blank? ? redirect_to(city_path) : render('index')
You can use present? method it will handle both nil
and blank
values
if (@city.name.present?)
redirect_to city_path
else
render 'index'
end
You can use like
if @city.name.present?
redirect_to city_path
else
render 'index'
end