Commit cd9f50a2 authored by Jacob Ysrael C. Chua's avatar Jacob Ysrael C. Chua

foopie added quiz2

parent d2b7b6b2
module Admin
class PostsController < ApplicationController
def index
@posts = Post.all
render "admin/posts/index.html.erb"
end
def edit
@post = Post.find(params[:id])
end
def update
@post = Post.find(params[:id])
if @post.update(post_params())
redirect_to admin_post_path(@post.id)
else
render "admin/posts/edit.html.erb"
end
end
def new
@post = Post.new
render "admin/posts/new.html.erb"
end
def create
@post = Post.new(post_params())
if @post.save
redirect_to admin_post_path(@post.id)
else
render "admin/posts/new.html.erb"
end
end
def show
@post = Post.find(params[:id])
render "admin/posts/show.html.erb"
end
def destroy
@post = Post.find(params[:id])
@post.destroy!
redirect_to admin_posts_path
end
def post_params
params.require(:post).permit!
end
end
end
\ No newline at end of file
class PostsController < ApplicationController
def index
@posts = Post.all
render "posts/index.html.erb"
end
def edit
@post = Post.find(params[:id])
end
def update
@post = Post.find(params[:id])
if @post.update(post_params())
redirect_to post_path(@post.id)
else
render "posts/edit.html.erb"
end
end
def new
@post = Post.new
render "posts/new.html.erb"
end
def create
@post = Post.new(post_params())
if @post.save
redirect_to post_path(@post.id)
else
render "posts/new.html.erb"
end
end
def show
@post = Post.find(params[:id])
render "posts/show.html.erb"
end
def destroy
@post = Post.find(params[:id])
@post.destroy!
redirect_to posts_path
end
def post_params
params.require(:post).permit!
end
end
class Post < ActiveRecord::Base
end
<h1>My Blog</h1>
<%= link_to "Show Posts as User", posts_path %>
<%= link_to "Manage Posts as Admin", admin_posts_path %>
<%= simple_form_for(@post) do |f| %>
<%= f.input :title %>
<%= f.input :category, as: :select, collection:["Dota 2", "LoL"] %>
<%= f.input :article %>
<%= f.submit %>
<% end %>
<h1>Edit Post</h1>
<%= render partial: "form" %>
<%= link_to "Back to Posts", admin_posts_path %>
<h1>Blog Posts</h1>
<%= link_to("New Post", new_admin_post_path) %>
<table width="100%">
<tr>
<th>Title</th>
<th>Category</th>
<th>Article</th>
<th>Actions</th>
</tr>
<% @posts.each do |post| %>
<tr>
<td><%= post.title %></td>
<td><%= post.category %></td>
<td><%= post.article %></td>
<td>
<%= link_to "Show", admin_post_path(post.id) %>
<%= link_to "Edit", edit_admin_post_path(post.id) %>
<%= link_to "Delete", admin_post_path(post.id), method: :delete, data: { confirm: 'Are you sure?' } %>
</td>
</tr>
<% end %>
</table>
<h1><%= @post.title %></h1>
<h3><%= @post.category %></h3>
<p>
<%= @post.article %>
</p>
<hr>
<%= link_to "Back to Posts", admin_posts_path %>
<h1>My Blog</h1>
<%= link_to "Show Posts as User", posts_path %>
<%= link_to "Manage Posts as Admin", admin_posts_path %>
<%= simple_form_for(@post) do |f| %>
<%= f.input :title %>
<%= f.input :category, as: :select, collection:["Dota 2", "LoL"] %>
<%= f.input :article %>
<%= f.submit %>
<% end %>
<h1>Edit Post</h1>
<%= render partial: "form" %>
<%= link_to "Back to Posts", posts_path %>
<h1>Blog Posts</h1>
<table width="100%">
<tr>
<th>Title</th>
<th>Category</th>
<th>Article</th>
<th>Actions</th>
</tr>
<% @posts.each do |post| %>
<tr>
<td><%= post.title %></td>
<td><%= post.category %></td>
<td><%= post.article %></td>
<td>
<%= link_to "Show", post_path(post.id) %>
</td>
</tr>
<% end %>
</table>
<h1><%= @post.title %></h1>
<h3><%= @post.category %></h3>
<p>
<%= @post.article %>
</p>
<hr>
<%= link_to "Back to Posts", posts_path %>
Rails.application.routes.draw do
root to: "pages#index"
resources :posts
namespace :admin do
resources :posts
end
end
source 'http://rubygems.org'
gem 'skeleton-rails', :git => 'https://github.com/helios-technologies/skeleton-rails'
gem 'simple_form'
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use sqlite3 as the database for Active Record
......@@ -44,3 +44,4 @@ end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'simple_form'
\ No newline at end of file
GIT
remote: https://github.com/helios-technologies/skeleton-rails
revision: 6e46649d29006643b33c95b82bc9d0e28df2f8cc
specs:
skeleton-rails (1.1.0)
GEM
remote: http://rubygems.org/
remote: https://rubygems.org/
specs:
actionmailer (4.2.6)
actionpack (= 4.2.6)
......@@ -79,9 +73,6 @@ GEM
mini_portile2 (2.1.0)
minitest (5.9.0)
multi_json (1.12.1)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
nokogiri (1.6.8-x86-mingw32)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
......@@ -136,7 +127,6 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.11)
sqlite3 (1.3.11-x86-mingw32)
thor (0.19.1)
thread_safe (0.3.5)
......@@ -157,7 +147,6 @@ GEM
sprockets-rails (>= 2.0, < 4.0)
PLATFORMS
ruby
x86-mingw32
DEPENDENCIES
......@@ -169,7 +158,6 @@ DEPENDENCIES
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
simple_form
skeleton-rails!
sqlite3
turbolinks
tzinfo-data
......@@ -177,4 +165,4 @@ DEPENDENCIES
web-console (~> 2.0)
BUNDLED WITH
1.12.5
1.10.4
......@@ -12,20 +12,4 @@
*
*= require_tree .
*= require_self
*= require normalize
*= require skeleton
*/
body {
padding: 30px;
}
a {
padding: 10px;
padding-left: 0px;
transition: 0.2s cubic-bezier(.17,.67,.37,.79);
}
a:hover {
color: #28ccff !important;
}
\ No newline at end of file
module Admin
class BooksController < ApplicationController
def index
@books = Book.all
@search_by_name = params[:sbn]
@search_by_link = params[:sbl]
@filter_by_category = params[:fbc]
if @search_by_name.present?
@books = Book.where(name: @search_by_name)
end
if @search_by_link.present?
@books = Book.where(link: @search_by_link)
end
if @filter_by_category.present?
@books = Book.where(category: @filter_by_category)
end
render "admin/books/index.html.erb"
end
def create
@book = Book.new(book_params())
if @book.save
redirect_to admin_books_path(@book.id)
else
render "admin/books/new.html.erb"
end
end
def new
@book = Book.new
render "admin/books/new.html.erb"
end
def edit
@book = Book.find(params[:id])
end
def show
@book = Book.find(params[:id])
render "admin/books/show.html.erb"
end
def update
@book = Book.find(params[:id])
if @book.update(book_params())
redirect_to admin_books_path(@book.id)
else
render "admin/books/edit.html.erb"
end
end
def destroy
@book = Book.find(params[:id])
@book.destroy!
redirect_to admin_books_path
end
def book_params
params.require(:book).permit!
end
end
end
\ No newline at end of file
class BooksController < ApplicationController
def index
@books = Book.all
@search_by_name = params[:sbn]
@search_by_link = params[:sbl]
@filter_by_category = params[:fbc]
if @search_by_name.present?
@books = Book.where(name: @search_by_name)
end
if @search_by_link.present?
@books = Book.where(link: @search_by_link)
end
if @filter_by_category.present?
@books = Book.where(category: @filter_by_category)
end
render "books/index.html.erb"
end
def create
@book = Book.new(book_params())
if @book.save
redirect_to books_path(@book.id)
else
render "books/new.html.erb"
end
end
def new
@book = Book.new
render "books/new.html.erb"
end
def edit
@book = Book.find(params[:id])
end
def show
@book = Book.find(params[:id])
render "books/show.html.erb"
end
def update
@book = Book.find(params[:id])
if @book.update(book_params())
redirect_to books_path(@book.id)
else
render "books/edit.html.erb"
end
end
def destroy
@book = Book.find(params[:id])
@book.destroy!
redirect_to books_path
end
def book_params
params.require(:book).permit!
end
end
\ No newline at end of file
class PagesController < ApplicationController
def index
render "pages/index.html.erb"
render("pages/index.html.erb")
end
end
\ No newline at end of file
class Book < ActiveRecord::Base
validates :name, presence: true, uniqueness: true
validates :link, presence: true
validates :category, presence: true
end
<%= simple_form_for([:admin,@book]) do |b| %>
<%= b.input :name %>
<%= b.input :link %>
*Category<%= b.select :category, ['Fiction', 'Non-Fiction'] %>
<%= b.submit %>
<% end %>
<h1>Edit Book Entry</h1>
<%= render partial: "form" %>
<hr>
<b><%= link_to "I changed my mind", admin_books_path %></b>
\ No newline at end of file
<center><h1>BOOKS LIST</h1></center>
<center><%= form_tag("/books", method: "get") do %>
<input type="text" name="sbn"/>
<input type="submit" value="Search By Name">
<input type="text" name="sbl"/>
<input type="submit" value="Search By Link"/>
<input type="text" name="fbc"/>
<input type="submit" value="Filter By Category"/>
<% end %></center>
<center><table width="70%">
<thead>
<th><h2>Name</h2></th>
<th><h2>Link</h2></th>
<th><h2>Category</h2></th>
<th><h2>Action</h2></th>
</thead>
<tbody>
<% @books.each do |x| %>
<tr>
<td><center><%= x.name %></center></td>
<td><center><%= x.link %></center></td>
<td><center><%= x.category %></center></td>
<td><center>
<%= link_to "Show", admin_book_path(x.id) %>
<%= link_to "Edit", edit_admin_book_path(x.id) %>
<%= link_to "Delete", admin_book_path(x.id), method: :delete, data: {confirm: "Do you want to delete?"} %>
</center></td>
</tr>
<% end %>
</tbody>
</table></center>
<hr>
<h3><%= link_to("See all books", admin_books_path) %> </h3>
<h3><%= link_to("Create New", new_admin_book_path) %></h3>
<a href="../"><h3>Back to Home</h3></a>
\ No newline at end of file
<h1>New Post</h1>
<h1>New Book</h1>
<%= render partial: "form" %>
<%= link_to "Back to Posts", admin_posts_path %>
<h3><%= link_to "See Books", admin_books_path %></h3>
\ No newline at end of file
<h1><%= @book.name %></h1>
<h3>Link: <%= @book.link %></h3>
<h3>Category: <%= @book.category %></h3>
<%= link_to("Back to Books", admin_books_path) %>
\ No newline at end of file
<%= simple_form_for(@book) do |b| %>
<%= b.input :name %>
<%= b.input :link %>
*Category<%= b.select :category, ['Fiction', 'Non-Fiction'] %>
<%= b.submit %>
<% end %>
<h1>Edit Book Entry</h1>
<%= render partial: "form" %>
<hr>
<b><%= link_to "I changed my mind", books_path %></b>
\ No newline at end of file
<center><h1>BOOKS LIST</h1></center>
<center><%= form_tag("/books", method: "get") do %>
<input type="text" name="sbn"/>
<input type="submit" value="Search By Name">
<input type="text" name="sbl"/>
<input type="submit" value="Search By Link"/>
<input type="text" name="fbc"/>
<input type="submit" value="Filter By Category"/>
<% end %></center>
<center><table width="70%">
<thead>
<th><h2>Name</h2></th>
<th><h2>Link</h2></th>
<th><h2>Category</h2></th>
<th><h2>Action</h2></th>
</thead>
<tbody>
<% @books.each do |x| %>
<tr>
<td><center><%= x.name %></center></td>
<td><center><%= x.link %></center></td>
<td><center><%= x.category %></center></td>
<td><center>
<%= link_to "Show", book_path(x.id) %>
</center></td>
</tr>
<% end %>
</tbody>
</table></center>
<hr>
<h3><%= link_to("See all books", books_path) %> </h3>
<a href="../"><h3>Back to Home</h3></a>
\ No newline at end of file
<h1>New Post</h1>
<h1>New Book</h1>
<%= render partial: "form" %>
<%= link_to "Back to Posts", posts_path %>
<h3><%= link_to "See Books", books_path %></h3>
\ No newline at end of file
<h1><%= @book.name %></h1>
<h3>Link: <%= @book.link %></h3>
<h3>Category: <%= @book.category %></h3>
<%= link_to("Back to Books", books_path) %>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>Blog</title>
<title>BookmarksCrudAdmin</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
Jacob Chua 140911<center><h1>BOOKMARKS</h1></center>
<hr>
<%= yield %>
</body>
</html>
<center><h1>Welcome To My Bookmark Application!</h1>
<%= link_to "Go to Bookmarks List", books_path%>
<%= link_to "Admin", admin_books_path %>
\ No newline at end of file
......@@ -6,7 +6,7 @@ require 'rails/all'
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Blog
module BookmarksCrud
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
......
# Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, key: '_blog_session'
Rails.application.config.session_store :cookie_store, key: '_bookmarks_crud_session'
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Wrappers are used by the form builder to generate a
# complete input. You can remove any component from the
# wrapper, change the order or even add your own to the
# stack. The options given below are used to wrap the
# whole input.
config.wrappers :default, class: :input,
hint_class: :field_with_hint, error_class: :field_with_errors do |b|
## Extensions enabled by default
# Any of these extensions can be disabled for a
# given input by passing: `f.input EXTENSION_NAME => false`.
# You can make any of these extensions optional by
# renaming `b.use` to `b.optional`.
# Determines whether to use HTML5 (:email, :url, ...)
# and required attributes
b.use :html5
# Calculates placeholders automatically from I18n
# You can also pass a string as f.input placeholder: "Placeholder"
b.use :placeholder
## Optional extensions
# They are disabled unless you pass `f.input EXTENSION_NAME => true`
# to the input. If so, they will retrieve the values from the model
# if any exists. If you want to enable any of those
# extensions by default, you can change `b.optional` to `b.use`.
# Calculates maxlength from length validations for string inputs
b.optional :maxlength
# Calculates pattern from format validations for string inputs
b.optional :pattern
# Calculates min and max from length validations for numeric inputs
b.optional :min_max
# Calculates readonly automatically from readonly attributes
b.optional :readonly
## Inputs
b.use :label_input
b.use :hint, wrap_with: { tag: :span, class: :hint }
b.use :error, wrap_with: { tag: :span, class: :error }
## full_messages_for
# If you want to display the full error message for the attribute, you can
# use the component :full_error, like:
#
# b.use :full_error, wrap_with: { tag: :span, class: :error }
end
# The default wrapper to be used by the FormBuilder.
config.default_wrapper = :default
# Define the way to render check boxes / radio buttons with labels.
# Defaults to :nested for bootstrap config.
# inline: input + label
# nested: label > input
config.boolean_style = :nested
# Default class for buttons
config.button_class = 'btn'
# Method used to tidy up errors. Specify any Rails Array method.
# :first lists the first message for each field.
# Use :to_sentence to list all errors for each field.
# config.error_method = :first
# Default tag used for error notification helper.
config.error_notification_tag = :div
# CSS class to add for error notification helper.
config.error_notification_class = 'error_notification'
# ID to add for error notification helper.
# config.error_notification_id = nil
# Series of attempts to detect a default label method for collection.
# config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
# Series of attempts to detect a default value method for collection.
# config.collection_value_methods = [ :id, :to_s ]
# You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
# config.collection_wrapper_tag = nil
# You can define the class to use on all collection wrappers. Defaulting to none.
# config.collection_wrapper_class = nil
# You can wrap each item in a collection of radio/check boxes with a tag,
# defaulting to :span.
# config.item_wrapper_tag = :span
# You can define a class to use in all item wrappers. Defaulting to none.
# config.item_wrapper_class = nil
# How the label text should be generated altogether with the required text.
# config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }
# You can define the class to use on all labels. Default is nil.
# config.label_class = nil
# You can define the default class to be used on forms. Can be overriden
# with `html: { :class }`. Defaulting to none.
# config.default_form_class = nil
# You can define which elements should obtain additional classes
# config.generate_additional_classes_for = [:wrapper, :label, :input]
# Whether attributes are required by default (or not). Default is true.
# config.required_by_default = true
# Tell browsers whether to use the native HTML5 validations (novalidate form option).
# These validations are enabled in SimpleForm's internal config but disabled by default
# in this configuration, which is recommended due to some quirks from different browsers.
# To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
# change this configuration to true.
config.browser_validations = false
# Collection of methods to detect if a file type was given.
# config.file_methods = [ :mounted_as, :file?, :public_filename ]
# Custom mappings for input types. This should be a hash containing a regexp
# to match as key, and the input type that will be used when the field name
# matches the regexp as value.
# config.input_mappings = { /count/ => :integer }
# Custom wrappers for input types. This should be a hash containing an input
# type as key and the wrapper that will be used for all inputs with specified type.
# config.wrapper_mappings = { string: :prepend }
# Namespaces where SimpleForm should look for custom input classes that
# override default inputs.
# config.custom_inputs_namespaces << "CustomInputs"
# Default priority for time_zone inputs.
# config.time_zone_priority = nil
# Default priority for country inputs.
# config.country_priority = nil
# When false, do not use translations for labels.
# config.translate_labels = true
# Automatically discover new inputs in Rails' autoload path.
# config.inputs_discovery = true
# Cache SimpleForm inputs discovery
# config.cache_discovery = !Rails.env.development?
# Default class for inputs
# config.input_class = nil
# Define the default class of the input wrapper of the boolean input.
config.boolean_label_class = 'checkbox'
# Defines if the default input wrapper class should be included in radio
# collection wrappers.
# config.include_default_input_wrapper_class = true
# Defines which i18n scope will be used in Simple Form.
# config.i18n_scope = 'simple_form'
end
en:
simple_form:
"yes": 'Yes'
"no": 'No'
required:
text: 'required'
mark: '*'
# You can uncomment the line below if you need to overwrite the whole required html.
# When using html, text and mark won't be used.
# html: '<abbr title="required">*</abbr>'
error_notification:
default_message: "Please review the problems below:"
# Examples
# labels:
# defaults:
# password: 'Password'
# user:
# new:
# email: 'E-mail to sign in.'
# edit:
# email: 'E-mail.'
# hints:
# defaults:
# username: 'User name to sign in.'
# password: 'No special characters, please.'
# include_blanks:
# defaults:
# age: 'Rather not say'
# prompts:
# defaults:
# age: 'Select your age'
Rails.application.routes.draw do
root(to: "pages#index")
resources :books
namespace :admin do
resources :books
end
end
......@@ -11,10 +11,10 @@
# if you're sharing your code publicly.
development:
secret_key_base: 4764411a76b0506050a5f9a259a7206d6052f006856fa44a638c78c0c26cdda9c20fdf3e8f64ee4e62eb60e09665d5dce79428c845b042f0b2f2ce621c541895
secret_key_base: 788b285cddcfe74393ab8bf12aba076ee12e5d5b05a8ed793d454ef0f345afe1dd34169a8507602affaff3045baebb6b92ca230dee65d944cb2e4394fee0f550
test:
secret_key_base: 16baeb2da38d7e01c489cd7080ec64a82b0be9529b13540a4462f13c82ee0a3a738f75f53f27b84e5fb0c1c4f7523c00611de518bac18e1da71c902bbb93bf34
secret_key_base: 7c67dfa06cabf6991f97fc24a46bc215bc476e5295ccab8e8e4f9adc024db266d7fa43188285f4d10f8893a9a28b9992b3f730aa49e1e57b617b133e07544c63
# Do not keep production secrets in the repository,
# instead read values from the environment.
......
class CreatePosts < ActiveRecord::Migration
class CreateBooks < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :article
create_table :books do |t|
t.string :name
t.string :link
t.string :category
t.timestamps null: false
......
......@@ -11,11 +11,11 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160712051047) do
ActiveRecord::Schema.define(version: 20160712080725) do
create_table "posts", force: :cascade do |t|
t.string "title"
t.text "article"
create_table "books", force: :cascade do |t|
t.string "name"
t.string "link"
t.string "category"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
......
<%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
<%%= f.error_notification %>
<div class="form-inputs">
<%- attributes.each do |attribute| -%>
<%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
<%- end -%>
</div>
<div class="form-actions">
<%%= f.button :submit %>
</div>
<%% end %>
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
title: MyString
article: MyText
name: MyString
link: MyString
category: MyString
two:
title: MyString
article: MyText
name: MyString
link: MyString
category: MyString
require 'test_helper'
class PostTest < ActiveSupport::TestCase
class BookTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment