diff --git a/Gemfile b/Gemfile index c6727ee..c669603 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 81f0e8d..02d8d01 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app/assets/javascripts/links.coffee b/app/assets/javascripts/links.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/links.coffee @@ -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/ diff --git a/app/assets/stylesheets/custom.scss b/app/assets/stylesheets/custom.scss new file mode 100644 index 0000000..8a55a08 --- /dev/null +++ b/app/assets/stylesheets/custom.scss @@ -0,0 +1,3 @@ +.bottom-spacer { + margin-bottom: 10px; +} diff --git a/app/assets/stylesheets/links.scss b/app/assets/stylesheets/links.scss new file mode 100644 index 0000000..220eb70 --- /dev/null +++ b/app/assets/stylesheets/links.scss @@ -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/ diff --git a/app/controllers/links_controller.rb b/app/controllers/links_controller.rb new file mode 100644 index 0000000..b9b0589 --- /dev/null +++ b/app/controllers/links_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..0005769 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,5 @@ module ApplicationHelper + def icon(icon) + content_tag(:i, icon.to_s, class: 'material-icons') + end end diff --git a/app/helpers/links_helper.rb b/app/helpers/links_helper.rb new file mode 100644 index 0000000..f6bc988 --- /dev/null +++ b/app/helpers/links_helper.rb @@ -0,0 +1,2 @@ +module LinksHelper +end diff --git a/app/models/link.rb b/app/models/link.rb new file mode 100644 index 0000000..03002b0 --- /dev/null +++ b/app/models/link.rb @@ -0,0 +1,4 @@ +class Link < ActiveRecord::Base + validates :name, presence: true, + uniqueness: true +end diff --git a/app/views/application/_navbar.html.slim b/app/views/application/_navbar.html.slim index eb19bfa..e38b25e 100644 --- a/app/views/application/_navbar.html.slim +++ b/app/views/application/_navbar.html.slim @@ -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 diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index 9598aa6..2fc88fd 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -11,8 +11,8 @@ html = csrf_meta_tags body + == render 'flash_messages', flash: flash == render 'navbar' .container - == render 'flash_messages', flash: flash = yield diff --git a/app/views/links/_form.html.slim b/app/views/links/_form.html.slim new file mode 100644 index 0000000..d33fbbc --- /dev/null +++ b/app/views/links/_form.html.slim @@ -0,0 +1,6 @@ += simple_form_for @link do |f| + .row + .col.s12 + = f.input :name + = f.input :description + = f.button :button diff --git a/app/views/links/edit.html.slim b/app/views/links/edit.html.slim new file mode 100644 index 0000000..fbedb45 --- /dev/null +++ b/app/views/links/edit.html.slim @@ -0,0 +1 @@ +== render 'form' diff --git a/app/views/links/index.html.slim b/app/views/links/index.html.slim new file mode 100644 index 0000000..717e94d --- /dev/null +++ b/app/views/links/index.html.slim @@ -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' diff --git a/app/views/links/new.html.slim b/app/views/links/new.html.slim new file mode 100644 index 0000000..fbedb45 --- /dev/null +++ b/app/views/links/new.html.slim @@ -0,0 +1 @@ +== render 'form' diff --git a/config/initializers/simple_form_materialize.rb b/config/initializers/simple_form_materialize.rb new file mode 100644 index 0000000..dc95a88 --- /dev/null +++ b/config/initializers/simple_form_materialize.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index eb69c8e..5539ee5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/db/migrate/20151001151519_create_links.rb b/db/migrate/20151001151519_create_links.rb new file mode 100644 index 0000000..9d7bf4e --- /dev/null +++ b/db/migrate/20151001151519_create_links.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index dabf3ed..2435f4d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"