# In search result drop box: add given name next to username

**URL:** <https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735>\
**Category:** UX\
**Created:** [2016年八月17日 13:07 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735 "2016-08-17T13:07:25Z")\
**Posts on this page:** 14\
**Page:** 2

<div class="post-metadata">

**Author:** ![erlend\_sh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erlend_sh/32/119475_2.png) [@erlend\_sh](https://meta.discourse.org/u/erlend_sh)\
**Post date:** [2017年二月15日 15:07 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/21 "2017-02-15T15:07:50Z")

</div>

> [@designbygio](#):
>
> username in bold and blue color, name normal font-weight and grey color.Is that correct?

Wups, no. Sorry about the confusion; I guess you must have read the email version of my reply? I kept editing my post after that. As you can [see above](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/16), I’m describing the same thing as Sam [reiterated here](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/19).

@rriemann you’re right that there’s an inconsistency there, but email conventions are a bit different. Practically any clickable element in an email notification should either be a button or have link-styling (i.e. either blue or underlined), because in theory there shouldn’t be that many of them. In the interactive app we need to de-emphasise most of these clickables, because there’s so many of them. The fact that they can be interacted with is made obvious through context such as it appearing in a drop-down.

---

<div class="post-metadata">

**Author:** ![designbygio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/designbygio/32/122415_2.png) [@designbygio](https://meta.discourse.org/u/designbygio)\
**Post date:** [2017年二月15日 15:58 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/22 "2017-02-15T15:58:06Z")

</div>

All clear now! thanks

---

<div class="post-metadata">

**Author:** ![designbygio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/designbygio/32/122415_2.png) [@designbygio](https://meta.discourse.org/u/designbygio)\
**Post date:** [2017年二月15日 21:42 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/23 "2017-02-15T21:42:07Z")

</div>

unfortunately when i restart the branch to fix the style, i got the same error Robert got [already](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/10) here.

The `u` (user) object in js doesn’t get `name` information.  
If `:name` is added to `basic_user_serialize.rb` error is raised.

I personally think the error is coming from these line of `ams_include_without_root.rb`

```plaintext
      if options[:include] == nil
        if @options.key?(:include)
          options[:include] = @options[:include].include?(name)
        elsif @options.include?(:exclude)
          options[:include] = !@options[:exclude].include?(name)
        end
      end

```

Is possible that `options[:include]` is never true, therefore is always false?  
If i put `binding.pry` here:

```plaintext
association = association_class.new(name, self, options)

      if association.embed_ids?
        node[association.key] = association.serialize_ids

        if association.embed_in_root? && hash.nil?
          # Don't raise an error!
        elsif association.embed_in_root? && association.embeddable?
          binding.pry
          merge_association hash, association.root, association.serializables, unique_values
        end
      elsif association.embed_objects?
        node[association.key] = association.serialize
      end

```

and i check what’s inside `options` i see `name: nil`

So my questions are:

- Is name correctly saved in options?
- I guess this Active Model Serialize it doesn’t pass attributes just to basic\_user\_serialize.

If it pass `name` to other part of the app and there is successfully passed to the frontend, then the problem come from how the attribues is passed. Otherwise problem is coming from active model serialize.

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2017年二月15日 23:03 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/24 "2017-02-15T23:03:24Z")

</div>

There is some code smell we need to clean up with our serializer

> <https://github.com/discourse/discourse/blob/main/app/serializers/basic_user_serializer.rb#L4-L6>

the base serializer is deciding for serializers that inherit off it if it should include names or not… it just does not seem right at all.

I would not include name in basic user serializer, this is something that a specific user serializer used for search should add.

---

<div class="post-metadata">

**Author:** ![designbygio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/designbygio/32/122415_2.png) [@designbygio](https://meta.discourse.org/u/designbygio)\
**Post date:** [2017年二月16日 13:23 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/25 "2017-02-16T13:23:34Z")

</div>

Unfortuantely my knowledge of ruby are very very limited.  
if you think is something i can do it (this user serliazer for search) with some guidence, i’m happy to try.  
But if it require more understanding of RoR, i unfortunately will have to setp back from this PR 😔

---

<div class="post-metadata">

**Author:** ![designbygio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/designbygio/32/122415_2.png) [@designbygio](https://meta.discourse.org/u/designbygio)\
**Post date:** [2017年二月21日 12:26 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/26 "2017-02-21T12:26:43Z")

</div>

Keep looking into this issue and i find out that some pages display without errors the name like `/users` or `/admin` and some others give the `MissingAttributeError` like home page.  
Whenever i check if name is enable (both FE and BE) i always get `true`.

@rriemann how did you identify `Basic_user_serializer` has the one connected to search result?  
I’m try to understand where the attrs in widget are coming from.. maybe @fantasticfears you know? Previously you said [quote=“fantasticfears, post:3, topic:48735”]  
After that, Ember model and widget kicks in.  
[/quote]

how exactly?

@sam clean up basic\_user\_serialize wouldn’t be quite big task? Look like is it used all over the app.  
I notice some other serializer which inherit from basic\_user, use the `:name` attribute. So maybe i have to find the one that work directly with search result and add `:name` to that search results?

---

<div class="post-metadata">

**Author:** ![rriemann](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rriemann/32/115238_2.png) [@rriemann](https://meta.discourse.org/u/rriemann)\
**Post date:** [2017年二月21日 16:16 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/27 "2017-02-21T16:16:05Z")

</div>

I am sorry, I reported all my findings and I have never been an Ember specialist. I guess I just grep-ed through the source code.

---

<div class="post-metadata">

**Author:** ![fantasticfears](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fantasticfears/32/119608_2.png) [@fantasticfears](https://meta.discourse.org/u/fantasticfears)\
**Post date:** [2017年二月22日 09:25 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/28 "2017-02-22T09:25:43Z")

</div>

> [@designbygio](#):
>
> I’m try to understand where the attrs in widget are coming from..

Widgets in Discourse usually are mounted upon a component or directly by `{{mount-widget}}`. So the widget retrieves the model is as the same as how the component binds to the model.

Search results should come from `GroupedSearchResultsSerializer`. As @sam’s suggest, you can replace the `BasicUserSerializer` with a new one specified for the search as well as some cleanup for that `include_name?` probably.

---

<div class="post-metadata">

**Author:** ![designbygio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/designbygio/32/122415_2.png) [@designbygio](https://meta.discourse.org/u/designbygio)\
**Post date:** [2017年二月22日 11:34 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/29 "2017-02-22T11:34:50Z")

</div>

Thank you @fantasticfears  
I was able to create a new Serializer specific for search and use it in place of `BasicUserSerializer` and look like is working.. in all the pages.

This is how my `SearchResultUserSerializer` look like:

```plaintext
class SearchResultUserSerializer < ApplicationSerializer
  attributes :id, :username, :avatar_template, :name

  def avatar_template
    if Hash === object
      User.avatar_template(user[:username], user[:uploaded_avatar_id])
    else
      user.try(:avatar_template)
    end
  end

  def user
    object[:user] || object
  end

end

```

Does it make sense? (again, no experience with Ruby/RoR so not sure if is ok to simply get rid of `include_name?` method)

If the serializer is good, the style now look like this:

 ![](https://global.discourse-cdn.com/meta/original/3X/d/9/d9eb0a9f468f831136c91bb54e0ea909ec8ecc9c.png)

---

<div class="post-metadata">

**Author:** ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)\
**Post date:** [2017年三月1日 06:57 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/30 "2017-03-01T06:57:29Z")

</div>

@designbygio You can actually just inherit from `BasicUserSerializer` like so

```plaintext
class SearchResultUserSerializer < BasicUserSerializer
  attributes :name  
end

```

Generally, it is not recommended to duplicate logic in the code base.

---

<div class="post-metadata">

**Author:** ![designbygio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/designbygio/32/122415_2.png) [@designbygio](https://meta.discourse.org/u/designbygio)\
**Post date:** [2017年三月1日 12:18 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/31 "2017-03-01T12:18:25Z")

</div>

Good point!  
Here is the new one:

> <https://github.com/gsambrotta/discourse/blob/d308638a1815a62cabac711a81b9d634a90bc219/app/serializers/search_result_user_serializer.rb>

---

<div class="post-metadata">

**Author:** ![designbygio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/designbygio/32/122415_2.png) [@designbygio](https://meta.discourse.org/u/designbygio)\
**Post date:** [2017年三月7日 13:55 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/32 "2017-03-07T13:55:58Z")

</div>

Done and merged!  
[https://github.com/discourse/discourse/pull/4706](https://github.com/discourse/discourse/pull/4706)

Final result:

 ![](https://global.discourse-cdn.com/meta/original/3X/7/a/7a2ce4b6ff822701623a503912c5cf1e30dd1b06.png)

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2017年三月7日 14:00 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/33 "2017-03-07T14:00:09Z")

</div>

excellent job, looks awesome!

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2017年三月7日 14:00 UTC](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735/34 "2017-03-07T14:00:12Z")

</div>



[上一頁](https://meta.discourse.org/t/in-search-result-drop-box-add-given-name-next-to-username/48735.md?page=1)
