I have Acts_As_Taggable Plugin working. I have a HR controller and a
sales controller.
I have a document in hr tagged whitepaper and a differnent document in
sales tagged whitepaper
when I am in hr I see the hr document tagged with whitepaper and not
the sale document (what I want). but if I click on the tag whitepaper
I return two documents, hr and sales. I just want to return the hr
document because the sales document is for sales people only.
I’m guessing I need to filter it somewhere but haven’t found the place
yet.
taggings db
create_table :taggings do |t|
t.column :tag_id, :integer #id of tagged object
t.column :taggable_id, :integer #type of object tagged
t.column :taggable_type, :string
end
I have Acts_As_Taggable Plugin working. I have a HR controller and a
sales controller.
I have a document in hr tagged whitepaper and a differnent document in
sales tagged whitepaper
when I am in hr I see the hr document tagged with whitepaper and not
the sale document (what I want). but if I click on the tag whitepaper
I return two documents, hr and sales. I just want to return the hr
document because the sales document is for sales people only.
I’m guessing I need to filter it somewhere but haven’t found the place yet.
I needed to do something similar. I used the “with_scope” method to do
the following (using your example). In my controller where I have the
method doing the find_tagged_with, I do this:
Document.with_scope( :find =>
{ :conditions => [“dept_id = ?”, department] }) do @docs = Document.find_tagged_with(…)
end
Any find_* that happen within the “with_scope” block will be constrained
with the conditions specified.
this is what happens when a newbie tries things he doesn’t fully
understand, and I thought not touching a computer over the weekend
would clear my head. it didn’t
in the line
{ :conditions => [“dept_id = ?”, department] }) do
i would either have HR of SALES?
If so me select doesn’t work. I get this error.
Mysql::Error: Unknown column ‘dept_id’ in ‘where clause’: SELECT *
FROM tags WHERE (dept_id = ‘hr’) AND (tags.name = ‘jim’ ) LIMIT 1
For some reason I’m thinking I need to filter on the taggalbe_type
column in the taggings table. but if I try that a get and error also.
unrecinizable table…
You may be able to do something like this (although it doesn’t quite
feel right to me for some reason … maybe it’s just that there’s too
much knowledge about the implementation of tagging … not sure). I
haven’t tried this, so I don’t know if it will work.
this is what happens when a newbie tries things he doesn’t fully
understand, and I thought not touching a computer over the weekend
would clear my head. it didn’t
in the line
{ :conditions => [“dept_id = ?”, department] }) do
i would either have HR of SALES?
If so me select doesn’t work. I get this error.
Mysql::Error: Unknown column ‘dept_id’ in ‘where clause’: SELECT *
FROM tags WHERE (dept_id = ‘hr’) AND (tags.name = ‘jim’ ) LIMIT 1
Sorry, I’d made some assumptions about the structure of your database.
I’d assumed that there was a Document and Dept model and that there was
a has_many relationship between Dept and Document. (ie. Dept has_many
Document and Document belongs_to Dept). That’s reflected in the above
“:conditions” line. That’s where the “dept_id” column would come from.
For some reason I’m thinking I need to filter on the taggalbe_type
column in the taggings table. but if I try that a get and error also.
unrecinizable table…
You may be able to do something like this (although it doesn’t quite
feel right to me for some reason … maybe it’s just that there’s too
much knowledge about the implementation of tagging … not sure). I
haven’t tried this, so I don’t know if it will work.