Question: I have a chip list, depending on the chip being clicked it will change. If user clicks the "gasoline" chip, template switches to source and destination input, if it clicks on hotel, it turns a tag input. My difficulty is to transform these template depedending on the condition

![enter image description here](https://i.stack.imgur.com/G3RB9.png)

```html
<div fxFlex="100">
  <mat-form-field fxFlex ngStyle.gt-sm="margin-left:30px" *ngIf="descriptionTags == 'default'; else tagDescription">
    <input matInput placeholder="Descrição" ngStyle.gt-sm="margin-left:30px">
  </mat-form-field>

  <ng-template #tagDescription>
    <mat-chip-list class="mat-chip-list">
      <mat-chip *ngFor="let tags of descriptionTags" value>
        {{tags.nameTag}}
      </mat-chip>
    </mat-chip-list>
  </ng-template>

  <ng-template #inputListTags>

    <h1>TAG INPUT LIST</h1>

  </ng-template>

  <ng-template #OriginDestinationReason>

    <h1>TAG Origin Destination adn Reason</h1>

  </ng-template>

  <ng-template #OriginDestination>

    <h1>TAG Origin Destination</h1>

  </ng-template>
</div>
```

Answer: 
Usually, when you see a bunch of if/elsif/elsif chained it's a code smell. I can think of two methods to write it cleaner:

```
def get_data
  case data
  when 'DataA' then 'I am data A'
  when 'DataB' then 'I am data B'
  when 'DataC' then 'I am data C'
  end
end

```

or

```
DATAS = {'DataA' => 'I am data A', 'DataB' => 'I am data B', 'DataC' => 'I am data C'}

def get_data
  ret_val = nil
  DATAS.each{|k,v| ret_val = v if k.includes?(data)}
  ret_val
end

```

---

For your second question, you'll need to query for unique values and then call the get\_data method

```
<% Product.distinct(:data).each do |f| %>
  <%= f.get_data %> 
<% end %>

```
Your question is pretty vague, but i'll try to answer it with what I think you mean. For the first question, if you want to be able to save only unique records, you can use `validates :<attribute>, uniqueness: true` on the model, which will make sure it's unique before saving it to the database. I'm not sure if this is what you meant, please elaborate a bit more on what `get_data` does and why you need to do that.

For the second question, you are returning strings, and the String class does not have the method `distinct`, that method belongs to `Array`, so you could do something like `result = []` and then `if <whatever> then arr << "Some string" end`. Again, share some more info so we can give a better answer.