Skip to content

Instantly share code, notes, and snippets.

@julioprotzek
Created December 14, 2013 14:39
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/7959944 to your computer and use it in GitHub Desktop.
Save julioprotzek/7959944 to your computer and use it in GitHub Desktop.
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 1.2'
gem 'simple_form'
gem 'slim-rails'
gem 'xray-rails', group: :development
gem 'pry-rails', group: :development
gem 'start'
/ - @articles = Article.all
/
/ - @article.limit(2)
/
/ - @articles = Article.where(category_id: 1)
/
/ - Time.now
/ - Date.today
/ - Date.today - 1.day
/ - Date.today - 2.weeks
/ - 1.week.from_now
/ - 2.days.ago
/ - 1.week.ago
/
/ - @articles = Article.where('published_at > ?', 1.week.ago)
- @articles = Article.order(published_at: :desc).order(:title)
h1 Artigos
table.table.table-striped
thead
tr
th Título
th Publicado em
th Categoria
th
tbody
- @articles.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'
c = Category.first
a = Article.new(title: 'Goleada', category: c, published_at: Time.now)
a.save
a = Article.find(1)
c = Category.find(2)
a.update(title: 'Novela', category: c)
a = Article.find(1)
a.destroy
bundle
rails console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment