Add links CRUD
This commit is contained in:
parent
fb390b7e00
commit
ccf4e75ee0
19 changed files with 170 additions and 7 deletions
1
Gemfile
1
Gemfile
|
@ -12,6 +12,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc
|
||||||
|
|
||||||
gem 'materialize-sass'
|
gem 'materialize-sass'
|
||||||
gem 'slim-rails'
|
gem 'slim-rails'
|
||||||
|
gem 'simple_form'
|
||||||
|
|
||||||
gem 'omniauth-reddit', :git => 'git://github.com/jackdempsey/omniauth-reddit.git'
|
gem 'omniauth-reddit', :git => 'git://github.com/jackdempsey/omniauth-reddit.git'
|
||||||
|
|
||||||
|
|
|
@ -149,6 +149,9 @@ GEM
|
||||||
sdoc (0.4.1)
|
sdoc (0.4.1)
|
||||||
json (~> 1.7, >= 1.7.7)
|
json (~> 1.7, >= 1.7.7)
|
||||||
rdoc (~> 4.0)
|
rdoc (~> 4.0)
|
||||||
|
simple_form (3.1.0)
|
||||||
|
actionpack (~> 4.0)
|
||||||
|
activemodel (~> 4.0)
|
||||||
slim (3.0.6)
|
slim (3.0.6)
|
||||||
temple (~> 0.7.3)
|
temple (~> 0.7.3)
|
||||||
tilt (>= 1.3.3, < 2.1)
|
tilt (>= 1.3.3, < 2.1)
|
||||||
|
@ -197,6 +200,7 @@ DEPENDENCIES
|
||||||
rails (= 4.2.4)
|
rails (= 4.2.4)
|
||||||
sass-rails (~> 5.0)
|
sass-rails (~> 5.0)
|
||||||
sdoc (~> 0.4.0)
|
sdoc (~> 0.4.0)
|
||||||
|
simple_form
|
||||||
slim-rails
|
slim-rails
|
||||||
spring
|
spring
|
||||||
sqlite3
|
sqlite3
|
||||||
|
|
3
app/assets/javascripts/links.coffee
Normal file
3
app/assets/javascripts/links.coffee
Normal 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/
|
3
app/assets/stylesheets/custom.scss
Normal file
3
app/assets/stylesheets/custom.scss
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.bottom-spacer {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
3
app/assets/stylesheets/links.scss
Normal file
3
app/assets/stylesheets/links.scss
Normal 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/
|
51
app/controllers/links_controller.rb
Normal file
51
app/controllers/links_controller.rb
Normal 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
|
|
@ -1,2 +1,5 @@
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
|
def icon(icon)
|
||||||
|
content_tag(:i, icon.to_s, class: 'material-icons')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
2
app/helpers/links_helper.rb
Normal file
2
app/helpers/links_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
module LinksHelper
|
||||||
|
end
|
4
app/models/link.rb
Normal file
4
app/models/link.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
class Link < ActiveRecord::Base
|
||||||
|
validates :name, presence: true,
|
||||||
|
uniqueness: true
|
||||||
|
end
|
|
@ -1,13 +1,15 @@
|
||||||
nav
|
nav.bottom-spacer
|
||||||
.container
|
.container
|
||||||
.nav-wrapper
|
.nav-wrapper
|
||||||
a href="#" class="brand-logo" DBZDokkan
|
a.brand-logo href="/" DBZDokkan
|
||||||
a href="#" data-activates="mobile" class="button-collapse"
|
a.button-collapse href="#" data-activates="mobile"
|
||||||
i class="material-icons" menu
|
i.material-icons menu
|
||||||
ul.right.hide-on-med-and-down
|
|
||||||
ul#mobile.side-nav
|
ul#mobile.side-nav
|
||||||
|
li= link_to 'Links', links_path
|
||||||
ul.right
|
ul.right
|
||||||
- if logged_in?
|
- if logged_in?
|
||||||
li= link_to 'Logout', logout_path, method: :delete
|
li= link_to 'Logout', logout_path, method: :delete
|
||||||
- else
|
- else
|
||||||
li= link_to 'Login', '/auth/reddit'
|
li= link_to 'Login', '/auth/reddit'
|
||||||
|
ul.right.hide-on-med-and-down
|
||||||
|
li= link_to 'Links', links_path
|
||||||
|
|
|
@ -11,8 +11,8 @@ html
|
||||||
= csrf_meta_tags
|
= csrf_meta_tags
|
||||||
|
|
||||||
body
|
body
|
||||||
|
== render 'flash_messages', flash: flash
|
||||||
== render 'navbar'
|
== render 'navbar'
|
||||||
|
|
||||||
.container
|
.container
|
||||||
== render 'flash_messages', flash: flash
|
|
||||||
= yield
|
= yield
|
||||||
|
|
6
app/views/links/_form.html.slim
Normal file
6
app/views/links/_form.html.slim
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
= simple_form_for @link do |f|
|
||||||
|
.row
|
||||||
|
.col.s12
|
||||||
|
= f.input :name
|
||||||
|
= f.input :description
|
||||||
|
= f.button :button
|
1
app/views/links/edit.html.slim
Normal file
1
app/views/links/edit.html.slim
Normal file
|
@ -0,0 +1 @@
|
||||||
|
== render 'form'
|
24
app/views/links/index.html.slim
Normal file
24
app/views/links/index.html.slim
Normal 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'
|
1
app/views/links/new.html.slim
Normal file
1
app/views/links/new.html.slim
Normal file
|
@ -0,0 +1 @@
|
||||||
|
== render 'form'
|
37
config/initializers/simple_form_materialize.rb
Normal file
37
config/initializers/simple_form_materialize.rb
Normal 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
|
|
@ -3,6 +3,7 @@ Rails.application.routes.draw do
|
||||||
get 'auth/failure', to: 'sessions#failure'
|
get 'auth/failure', to: 'sessions#failure'
|
||||||
delete 'logout', to: 'sessions#destroy', as: 'logout'
|
delete 'logout', to: 'sessions#destroy', as: 'logout'
|
||||||
|
|
||||||
|
resources :links
|
||||||
resources :welcome, only: [:index]
|
resources :welcome, only: [:index]
|
||||||
|
|
||||||
root to: 'welcome#index'
|
root to: 'welcome#index'
|
||||||
|
|
10
db/migrate/20151001151519_create_links.rb
Normal file
10
db/migrate/20151001151519_create_links.rb
Normal 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
|
|
@ -11,7 +11,14 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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|
|
create_table "users", force: :cascade do |t|
|
||||||
t.string "provider"
|
t.string "provider"
|
||||||
|
|
Loading…
Reference in a new issue