I don''t get why are you trying to do with regions
if you''re trying to filter houses by region, Why are there many regions
instead of only one?
On Saturday, April 20, 2013 1:53:35 PM UTC-7, Ruby-Forum.com User
wrote:>
> Hi,
>
> Already 2 ful days of trial and error...grgr. Can someone help me...
>
> part of my tag model:
>
> class Tag < ActiveRecord::Base
> has_many :taggings
> has_many :houses, through: :taggings
> end
> part of my house model
>
> class House < ActiveRecord::Base
> has_many :taggings
> has_many :tags, through: :taggings
>
> def self.tagged_with(name)
> Tag.find_by_name!(name).houses
> end
>
> def self.tag_counts
> Tag.select("tags.*, count(taggings.tag_id) as count").
> joins(:taggings).group("taggings.tag_id")
> end
>
> def tag_list
> tags.map(&:name).join(", ")
> end
>
> def tag_list=(names)
> self.tags = names.split(",").map do |n|
> Tag.where(name: n.strip).first_or_create!
> end
> end
> end
> part of my house controller:
>
> def index
> @country = Country.find(params[:country_id])
> @regions = @country.regions
>
> if params[:tag]
> @houses = House.tagged_with(params[:tag])
> else
> @houses = Find(:all)
> end
> house index view:
>
> .span9
> #container
> - @houses.each do |house|
> .item{:class => house.features_to_html_class }
> %article.chat.t_xs
> .article-base
> %section
> .span4
> %h2 #{link_to house.name, house_path(house)}
> %p
> When i visit house/tag/tagname
>
> i get the correct houses who are tagged with current tagname. So this
> works fine.
>
> But because i implemented a new nested resources setup
> (locale/country/region/houses) instead (/locale/houses) my view houses
> index changed in this:
>
> #container
> - @regions.each do |region|
> - region.houses.find_all do |house|
> .item{:class => house.features_to_html_class }
> %article.chat.t_xs
> .article-base
> %section
> .row
> .span4
> %h2 #{link_to house.name,
> country_region_house_path(@country, region, house)}
> %p
> But how i implement the tag feature in the new nested resources setup. I
> thought changing the "find_all" method in this:
>
> - @regions.each do |region|
> - region.houses.tagged_with(params[:tag]) do |house|
> This is not working...can someone advice/help me.
>
> Thanks..remco
>
> --
> Posted via http://www.ruby-forum.com/.
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/pIdURO2bbbYJ.
For more options, visit https://groups.google.com/groups/opt_out.