Skip to content

Instantly share code, notes, and snippets.

@JunichiIto
Created February 20, 2015 00:15
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 JunichiIto/891d1a8eb1f5efded351 to your computer and use it in GitHub Desktop.
Save JunichiIto/891d1a8eb1f5efded351 to your computer and use it in GitHub Desktop.
Skip JSON format in rails generate scaffold => http://stackoverflow.com/a/24104811/1058763
# Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.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', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
# Generate scaffold
rails g scaffold blog title content:text
invoke active_record
create db/migrate/20150220000736_create_blogs.rb
create app/models/blog.rb
invoke test_unit
create test/models/blog_test.rb
create test/fixtures/blogs.yml
invoke resource_route
route resources :blogs
invoke scaffold_controller
create app/controllers/blogs_controller.rb
invoke erb
create app/views/blogs
create app/views/blogs/index.html.erb
create app/views/blogs/edit.html.erb
create app/views/blogs/show.html.erb
create app/views/blogs/new.html.erb
create app/views/blogs/_form.html.erb
invoke test_unit
create test/controllers/blogs_controller_test.rb
invoke helper
create app/helpers/blogs_helper.rb
invoke test_unit
invoke assets
invoke coffee
create app/assets/javascripts/blogs.coffee
invoke scss
create app/assets/stylesheets/blogs.scss
invoke scss
create app/assets/stylesheets/scaffolds.scss
# Generate controller
class BlogsController < ApplicationController
before_action :set_blog, only: [:show, :edit, :update, :destroy]
# GET /blogs
def index
@blogs = Blog.all
end
# GET /blogs/1
def show
end
# GET /blogs/new
def new
@blog = Blog.new
end
# GET /blogs/1/edit
def edit
end
# POST /blogs
def create
@blog = Blog.new(blog_params)
if @blog.save
redirect_to @blog, notice: 'Blog was successfully created.'
else
render :new
end
end
# PATCH/PUT /blogs/1
def update
if @blog.update(blog_params)
redirect_to @blog, notice: 'Blog was successfully updated.'
else
render :edit
end
end
# DELETE /blogs/1
def destroy
@blog.destroy
redirect_to blogs_url, notice: 'Blog was successfully destroyed.'
end
private
# Use callbacks to share common setup or constraints between actions.
def set_blog
@blog = Blog.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def blog_params
params.require(:blog).permit(:title, :content)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment