Topic: Displaying tags from acts_as_taggable not working

I finally managed to get acts_as_taggable plugin to work for an app I've developed, the problem that's arising is that I cannot be able to display the tags for the particular record (a blog post in this case) I've tried the code from rails recipes:

post.tags.collect{|tag| tag.name}.join(", " )

but it displays a blank, no error, any guys out there using this plugin and managing to display the tags help?

Re: Displaying tags from acts_as_taggable not working

I've been using it for a while and it's working fine. Are you sure there are tags for the row in question? Have you poked at it in console?

Re: Displaying tags from acts_as_taggable not working

cwd wrote:

I've been using it for a while and it's working fine. Are you sure there are tags for the row in question? Have you poked at it in console?

I got it to work, seems that the post didn't have a tag, I even managed to hyperlink them so that when somebody clicks the particular tag it displays the related posts. One problem I had't foreseen was the fact that when some body has tagged a post with words that have spaces example Web 2.0, the tag is displayed okay but when you click on it you get a routing error like:

Routing Error

no route found to match "/peupe/tag/Web 2.0"


Any idea why this is happening?

Re: Displaying tags from acts_as_taggable not working

If you remove the spaces in the url, does it show the relevant results? If so, it may just be adding a matter of adding delete(" ") to the end of whatever you do to call the tags e.g.

<%= link_to tag, :controller => "peupe", :action => "tag", :tag => tag.delete(" ") %>

Or whatever your relevant code might be.

Re: Displaying tags from acts_as_taggable not working

alexpt wrote:

If you remove the spaces in the url, does it show the relevant results? If so, it may just be adding a matter of adding delete(" ") to the end of whatever you do to call the tags e.g.

<%= link_to tag, :controller => "peupe", :action => "tag", :tag => tag.delete(" ") %>

Or whatever your relevant code might be.

I think its more then that, after deleting the space I discovered that may be the dot. in a tag like "Web 2.0" might also be the issue because the routing error persists.

Re: Displaying tags from acts_as_taggable not working

Guys,
I'm still struggling with the same problem, all my tags that have whitespaces and dots "." in them throw major routing errors. Please help.

Cheers

Re: Displaying tags from acts_as_taggable not working

Just to check, there is no way to access the relevent page, e.g. /peupe/tag/Web 2.0 /peupe/tag/Web2.0 /peupe/tag/Web 20 /peupe/tag/Web20 all do not work? It might be an idea to create a tag with just a whitespace, and just a dot, to isolate the problem

If you can track diown the problem, you could then substitute the problem character before you save the tag, e.g.

tag = tag.sub('.', 'point')
#or
tag = tag.sub(' ', '_')

Alex

Re: Displaying tags from acts_as_taggable not working

alexpt wrote:

Just to check, there is no way to access the relevent page, e.g. /peupe/tag/Web 2.0 /peupe/tag/Web2.0 /peupe/tag/Web 20 /peupe/tag/Web20 all do not work? It might be an idea to create a tag with just a whitespace, and just a dot, to isolate the problem

If you can track diown the problem, you could then substitute the problem character before you save the tag, e.g.

tag = tag.sub('.', 'point')
#or
tag = tag.sub(' ', '_')

Alex

I did a replace for the spaces using the code above and tried to click on the tag when it had an underscore in it, the routing error occurred again. This still brings me back to the first point that may be the "." dot is one thats causing the problem. Any idea how I'll solve this problem?

Re: Displaying tags from acts_as_taggable not working

As I said, you could try substituting the "." with "point" or "dot" or something, although I think I may have found the cause of the problem.

Try adding :require => { :tag => /.*/ } to the end of your rout.

Alex

Re: Displaying tags from acts_as_taggable not working

alexpt wrote:

As I said, you could try substituting the "." with "point" or "dot" or something, although I think I may have found the cause of the problem.

Try adding :require => { :tag => /.*/ } to the end of your rout.

Alex

Safe to say that the modification to the route didn't work. Just wondering that if I replace the dot with the word "point" when I'm displaying the tag how do I then replace the word point with a  dot? and if I do replace won't the same routing error arise?

Re: Displaying tags from acts_as_taggable not working

have you tried looking into acts as polymorph? lets you  also paginate tags. i think i remember reading that acts as taggable with pagination has an issue?

Re: Displaying tags from acts_as_taggable not working

You would just do it in reverse:

<%= link_to tag.sub('point', '.'), :controller => "peupe", :action => "tag", :tag => tag %>

And that shouldn't cause the same issue, as how the link is displayed is nothing to do with what the actual URL is (and the URL is all the routes are concerned with).

Alex

Re: Displaying tags from acts_as_taggable not working

alexpt wrote:

You would just do it in reverse:

<%= link_to tag.sub('point', '.'), :controller => "peupe", :action => "tag", :tag => tag %>

And that shouldn't cause the same issue, as how the link is displayed is nothing to do with what the actual URL is (and the URL is all the routes are concerned with).

Alex

def display_tags(post)
      "Tags " + post.tags.collect { |tag| link_to tag.name.sub('point', '.'),
      { :controller => "/peupe", :action => "tag", :id => tag.name.delete(" ") },
      :rel => "tag"
    }.sort.join(", ")
 
end

Thats the code I use to display the tags now, previously it didn't have the sub method, when I click on the tag Web2.o the same routing error!! I don't know what I'm doing wrong but I'd like to know. All this is holding up my application!..Help a brother out

Re: Displaying tags from acts_as_taggable not working

And you're definetely doing

tag = tag.sub('.', 'point')

before the tag is saved? What the url of the page you're sent to?

Re: Displaying tags from acts_as_taggable not working

alexpt wrote:

And you're definetely doing

tag = tag.sub('.', 'point')

before the tag is saved? What the url of the page you're sent to?

This is my code for saving the tag:

def create
    params[:post].merge!({:user_id=>session[:user].id})
    @post = Post.new(params[:post])
   
    @post.tag_list = params[:post][:tags].sub('.', 'point')
    @post.tag_list = params[:post][:tags].delete(" ")
   
    if @post.save
      flash[:notice] = 'Post was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end
# code for displaying tag
def display_tags(post)
 
   "Tags " + post.tags.collect { |tag| link_to tag.name.sub('point', '.'),
      { :controller => "/peupe", :action => "tag", :id => tag.name.sub('point', '.') },
      :rel => "tag"
    }.sort.join(", ")
 
end
#the error
Routing Error

no route found to match "/peupe/tag/web2.0" with {:remote_ip=>"127.0.0.1", :method=>:get, :request_uri=>"/peupe/tag/web2.0", :protocol=>"http://", :content_type=>nil, :accepts=>"text/html,application/xml,image/png,text/plain,*/*", :port=>3000, :domain=>"localhost", :subdomain=>""}


What next?

Re: Displaying tags from acts_as_taggable not working

Try changing this:

{ :controller => "/peupe", :action => "tag", :id => tag.name.sub('point', '.') }

to this

{ :controller => "/peupe", :action => "tag", :id => tag.name }

Alex

Re: Displaying tags from acts_as_taggable not working

alexpt wrote:

Try changing this:

{ :controller => "/peupe", :action => "tag", :id => tag.name.sub('point', '.') }

to this

{ :controller => "/peupe", :action => "tag", :id => tag.name }

Alex

Doesn't work..cmon!! guys I need a working trying and tested solution...

Re: Displaying tags from acts_as_taggable not working

Your still getting the same error? If so, I'm all out of ideas sorry sad

Maybe you should look into a different plugin.