Send paramaters function @computed


I have a problem with a function in ES6. I have made a @computed function who calls a function in the ruby Tag component. It works fine.
But i need to send a parameter from my ES6 function to the component… and i can’t do it…
My ES6 function :

@computed('site.tags_by_category')   // here i think i have to send my parameter (category)
  tagsCategorie(reponse) {
        return reponse;

My ruby function :

def self.tags_by_category(category: nil)
      tags = exec_sql("SELECT, t.topic_count FROM tags t, topic_tags tt, topics top  WHERE t.topic_count>0 AND AND AND top.category_id IN 
      (SELECT id FROM categories WHERE id=? OR parent_category_id=?)", category, category)

I want to send my category from ecmascript to my ruby function… Or if it’s possible to know the category ID in the ruby Tag component, it can be another solution…
If someone can help me…
Ty, and sorry for my english.

(Robin Ward) #2

Computed properties shouldn’t be sending values to the server. They are used to calculate values based on other values. For example, area would be computed based on width * height.

You should only submit data to the server when a user performs an action, for example hitting a “submit” button. You’d add an action to your controller or component, which would then send the AJAX request across.


ty for your answer Robin…
In fact, i have no really action. I only want to display a tags cloud in my category page. So, i need to send the category to my Tag model.
The other solution could be to get directly the current category in my component (so not need to send a parameter) but i don’t know how to do…


I have tried to used a top_tags copy. So i can get the tags of my current category, it’s great… but i don’t have the tags count… How modify the top_tags in order to have the tags count?

def self.top_tags2(limit_arg: nil, category: nil, guardian: nil)
limit = limit_arg || SiteSetting.max_tags_in_filter_list
scope_category_ids = (guardian||

if category
  scope_category_ids &= ([] + category.subcategories.pluck(:id))

tags = DiscourseTagging.filter_allowed_tags(
  tags_by_count_query(limit: limit).where("topics.category_id in (?)", scope_category_ids),
  nil, # Don't pass guardian. You might not be able to use some tags, but should still be able to see where they've been used.
  category: category

tags.count(COUNT_ARG).map {|name, _| name}


The last lane only return the tags name, not the count… but i need to have the count to make the tags cloud…