ruby on rails
Quick question.
I'm trying to use the Acts-As-Taggable gem to search for multiple tags at the same time. The trick is, I want to search for any posts containing at least one of the tags. I've partially figured it out.
If in my songs controller I put
if params[:tag]
@songs = Song.tagged_with(["Hip-Hop-3, Hip-Hop-5"], :any => true)
elsif...
It will find all posts containing one or more of the tags.
The problem is, when I want to move these parameters into a ERB link_to
Here is my controller:
if params[:tag]
@songs = Song.tagged_with(params[:tag], :any => true).order("created_at DESC").paginate(:page => params[:page], :per_page => 36)
elsif
Here is my link_to
<%= link_to "House", tag_path(["Hip-Hop-5","Hip-Hop-3"]) %>
In this situation the URL is the same, http://localhost:3000/tags/Hip-Hop-5/Hip-Hop-3, but it doesn't show any of the posts like the previous method did.
Am I doing something wrong with the parameter?
OR
Is there a way I can have the tagged_with method search for tags containing certain characters. So find tags that contain the word "Hip-Hop" in it? Thank you!
Thank you,
Matt
You need to modify the url as follows:
<%= link_to "House", tag_path(tag: ["Hip-Hop-5","Hip-Hop-3"]) %>
I believe that the controller won't be able to find params[:tag] as per your link because it is not passed as hash to the method tag_path, using tag: params[:tag]
should ensure correct assignment of the params[:tag] to the parameters you were passing.
上一篇: R中定义的函数?
下一篇: 红宝石在轨道上