Created
November 30, 2013 13:03
-
-
Save julioprotzek/7718840 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Article < ActiveRecord::Base | |
validates :title, :category, presence: true | |
belongs_to :category | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Category < ActiveRecord::Base | |
validates :name, presence: true | |
has_many :articles | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- if notice | |
.alert.alert-info.alert-dismissable | |
button type="button" class="close" data-dismiss="alert" aria-hidden="true" × | |
= 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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