1
0

Add links CRUD

This commit is contained in:
Andrew Tomaka 2015-10-01 11:56:40 -04:00
parent fb390b7e00
commit ccf4e75ee0
19 changed files with 170 additions and 7 deletions

View File

@ -12,6 +12,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc
gem 'materialize-sass'
gem 'slim-rails'
gem 'simple_form'
gem 'omniauth-reddit', :git => 'git://github.com/jackdempsey/omniauth-reddit.git'

View File

@ -149,6 +149,9 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
simple_form (3.1.0)
actionpack (~> 4.0)
activemodel (~> 4.0)
slim (3.0.6)
temple (~> 0.7.3)
tilt (>= 1.3.3, < 2.1)
@ -197,6 +200,7 @@ DEPENDENCIES
rails (= 4.2.4)
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
simple_form
slim-rails
spring
sqlite3

View File

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

View File

@ -0,0 +1,3 @@
.bottom-spacer {
margin-bottom: 10px;
}

View File

@ -0,0 +1,3 @@
// Place all the styles related to the Links controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,51 @@
class LinksController < ApplicationController
before_action :set_link, only: [:show, :edit, :update, :destroy]
def index
@links = Link.all
end
def show
end
def new
@link = Link.new
end
def create
@link = Link.new(link_params)
if @link.save
redirect_to links_path, notice: 'Link was created'
else
render :new
end
end
def edit
end
def update
if @link.update(link_params)
redirect_to links_path, notice: 'Link was updated'
else
render :edit
end
end
def destroy
@link.destroy
redirect_to links_path, notice: 'Link was deleted'
end
private
def link_params
params.require(:link).permit(:name, :description)
end
def set_link
@link = Link.find(params[:id])
end
end

View File

@ -1,2 +1,5 @@
module ApplicationHelper
def icon(icon)
content_tag(:i, icon.to_s, class: 'material-icons')
end
end

View File

@ -0,0 +1,2 @@
module LinksHelper
end

4
app/models/link.rb Normal file
View File

@ -0,0 +1,4 @@
class Link < ActiveRecord::Base
validates :name, presence: true,
uniqueness: true
end

View File

@ -1,13 +1,15 @@
nav
nav.bottom-spacer
.container
.nav-wrapper
a href="#" class="brand-logo" DBZDokkan
a href="#" data-activates="mobile" class="button-collapse"
i class="material-icons" menu
ul.right.hide-on-med-and-down
a.brand-logo href="/" DBZDokkan
a.button-collapse href="#" data-activates="mobile"
i.material-icons menu
ul#mobile.side-nav
li= link_to 'Links', links_path
ul.right
- if logged_in?
li= link_to 'Logout', logout_path, method: :delete
- else
li= link_to 'Login', '/auth/reddit'
ul.right.hide-on-med-and-down
li= link_to 'Links', links_path

View File

@ -11,8 +11,8 @@ html
= csrf_meta_tags
body
== render 'flash_messages', flash: flash
== render 'navbar'
.container
== render 'flash_messages', flash: flash
= yield

View File

@ -0,0 +1,6 @@
= simple_form_for @link do |f|
.row
.col.s12
= f.input :name
= f.input :description
= f.button :button

View File

@ -0,0 +1 @@
== render 'form'

View File

@ -0,0 +1,24 @@
.row
.col.s12.right-align
= link_to 'New Link', new_link_path, class: 'btn'
.row
.col.s12
table.bordered.striped.highlight.responsive-table
thead
tr
th Name
th Description
th Actions
tbody
- @links.each do |link|
tr
td= link.name
td= link.description
td
= link_to icon(:subject), edit_link_path(link)
= link_to icon(:delete), link_path(link), method: :delete
.row
.col.s12
= link_to 'New Link', new_link_path, class: 'btn'

View File

@ -0,0 +1 @@
== render 'form'

View File

@ -0,0 +1,37 @@
SimpleForm.setup do |config|
config.error_notification_class = 'alert alert-danger'
config.button_class = 'waves-effect waves-light btn'
config.boolean_label_class = nil
config.wrappers :vertical_form, tag: 'div', class: 'input-field', error_class: 'has-error' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
b.optional :pattern
b.optional :min_max
b.optional :readonly
b.use :input
b.use :label
b.use :error, wrap_with: { tag: 'span', class: 'error-block' }
b.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
end
config.wrappers :vertical_boolean, tag: 'p', error_class: 'has-error' do |b|
b.use :html5
b.optional :readonly
b.use :input
b.use :label
b.use :error, wrap_with: { tag: 'span', class: 'error-block' }
b.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
end
config.wrappers :vertical_radio_and_checkboxes, tag: 'p', error_class: 'has-error' do |b|
b.use :html5
b.optional :readonly
b.use :input
b.use :label
b.use :error, wrap_with: { tag: 'span', class: 'error-block' }
b.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
end
end

View File

@ -3,6 +3,7 @@ Rails.application.routes.draw do
get 'auth/failure', to: 'sessions#failure'
delete 'logout', to: 'sessions#destroy', as: 'logout'
resources :links
resources :welcome, only: [:index]
root to: 'welcome#index'

View File

@ -0,0 +1,10 @@
class CreateLinks < ActiveRecord::Migration
def change
create_table :links do |t|
t.string :name
t.string :description
t.timestamps null: false
end
end
end

View File

@ -11,7 +11,14 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150930004246) do
ActiveRecord::Schema.define(version: 20151001151519) do
create_table "links", force: :cascade do |t|
t.string "name"
t.string "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", force: :cascade do |t|
t.string "provider"