Ruby on rails 如果参数存在,则不工作
我的url路径如下Ruby on rails 如果参数存在,则不工作,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-3.1,ruby-on-rails-3.2,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 3.1,Ruby On Rails 3.2,我的url路径如下 /locale/country/ /locale/country/region/ 型号: class Region belongs: country end class Country has_many: regions end 区域表中的外键国家/地区id 这是布局文件中导航部分的一部分 //block region - if params[:region].present? %ul.thumbnails - @region.ta
/locale/country/
/locale/country/region/
型号:
class Region
belongs: country
end
class Country
has_many: regions
end
区域表中的外键国家/地区id
这是布局文件中导航部分的一部分
//block region
- if params[:region].present?
%ul.thumbnails
- @region.tags.find_each(:conditions => "active_house = true") do |a|
%li.span2
.thumbnail
- a.attachments.limit(1).each do |b|
= image_tag(b.file.url)
.caption
%p
#{link_to a.h1, tag_country_region_houses_path(@country, @region, a.name), :class => 'btn-nav', class: active_class?(tag_houses_path(a.name))}
//block country
- else
%ul.thumbnails
- @country.tags.find_each(:conditions => "active_house = true") do |a|
%li.span2
.thumbnail
- a.attachments.limit(1).each do |b|
= image_tag(b.file.url)
.caption
%p
#{link_to a.h1, tag_country_houses_path(@country, a.name), :class => 'btn-nav', class: active_class?(tag_houses_path(a.name))}
当访客在路径/local/country上时,我想显示block country;当访客在/locale/country/region上时,我想显示block region
我想,如果参数[:region].出现?
就可以了。但不……我怎么能意识到这一点 尝试这样做:
if params.has_key?(:region)
或者,如果它存在但包含nil,您可以测试它:
unless params[:region].nil?
难道不是吗
class Region
belongs_to: country
end
而不是
class Region
belongs: country
end
排队前干杯
- if params[:region].present?
在你看来,试着改变这些线条
- p params[:region]
- p params[:region].present?
这可能会给你一些关于行为的线索。在
:region
参数中应该是什么?