---
# System prepended metadata

title: '[Ruby On Rails]將class加到html tag中'
tags: [Ruby On Rails]

---

# [Ruby On Rails]將class加到html tag中

###### tags: `Ruby On Rails`

使用以下語法:

```ruby
:class => "class_name"
```

範例1
```rust

 <% @articles.each do |f| %>
        <div>
          <h4><%= f.title %></h4>
          <p><%= f.text %></p>
        </div>
        <%= link_to  "detail", article_path(f) ,
        :class=>"btn btn-outline-secondary"%>
        
        <%= link_to  "edit", edit_article_path(f) ,
        :class=>"btn btn-outline-secondary"%>
        
        <%= link_to  "del", article_path(f),
        method: :delete,
        data:{ confirm: "confirm??"},
        class: "btn btn-outline-secondary"%>
<% end %>
```

範例2
```rust
<%= form_for @article do |f| %>

      <div class="form-group">
        <%= f.label :title, "title:" %>
        <%= f.text_field :title ,{:class => "form-control"}%>
      </div>
      <div class="form-group">
          <%= f.label :text, "text:" %>
          <%= f.text_area :text ,:class => "form-control"%>
      </div>

      <%= f.submit "save" ,:class => "btn btn-outline-secondary"%>

      <% end %>

```

