Skip to content

Instantly share code, notes, and snippets.

@julioprotzek
Created November 30, 2013 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julioprotzek/7718840 to your computer and use it in GitHub Desktop.
Save julioprotzek/7718840 to your computer and use it in GitHub Desktop.
class Article < ActiveRecord::Base
validates :title, :category, presence: true
belongs_to :category
end
class Category < ActiveRecord::Base
validates :name, presence: true
has_many :articles
end
h1 Artigos
table.table.table-striped
thead
tr
th Título
th Publicado em
th Categoria
th
tbody
- @articles.order(published_at: :desc).order(:title).each do |article|
tr
td = article.title
td = l article.published_at
td = article.category.name
td
.btn-group.pull-right
= link_to 'Ver', article, class: 'btn btn-default btn-sm'
= link_to 'Editar', edit_article_path(article), class: 'btn btn-default btn-sm'
= link_to 'Excluir', article, :confirm => 'Tem certeza?', :method => :delete, class: 'btn btn-default btn-sm'
br
= link_to 'Criar Artigo', new_article_path, class: 'btn btn-primary'
- if notice
.alert.alert-info.alert-dismissable
button type="button" class="close" data-dismiss="alert" aria-hidden="true" &times;
= notice
h1
= @article.title
.pull-right
= link_to 'Editar', edit_article_path(@article), class: 'btn btn-default'
hr
strong = @article.category.name
p = l @article.published_at
= simple_format @article.body
rails g migration add_category_id_to_articles category_id:integer:index
rake db:migrate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment