Skip to content

Commit 6e75c13

Browse files
committed
creating article
1 parent 49c6e59 commit 6e75c13

26 files changed

+204
-89
lines changed

Gemfile

+13-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,19 @@ gem 'jbuilder', '~> 2.0'
2323
# bundle exec rake doc:rails generates the API under doc/api.
2424
gem 'sdoc', '~> 0.4.0', group: :doc
2525

26-
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
27-
gem 'spring', group: :development
26+
group :development, :test do
27+
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
28+
gem 'byebug'
29+
# Access an IRB console on exception pages or by using <%= console %> in views
30+
gem 'web-console', '~> 2.0'
31+
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
32+
gem 'spring'
33+
# etter Errors replaces the standard Rails error page with a much better and more useful error page.
34+
gem 'better_errors'
35+
# Recommended for use only in debugging situations.
36+
gem 'binding_of_caller'
37+
end
38+
2839

2940
# Use ActiveModel has_secure_password
3041
# gem 'bcrypt', '~> 3.1.7'

Gemfile.lock

+20
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,25 @@ GEM
2828
thread_safe (~> 0.1)
2929
tzinfo (~> 1.1)
3030
arel (5.0.1.20140414130214)
31+
better_errors (2.1.1)
32+
coderay (>= 1.0.0)
33+
erubis (>= 2.6.6)
34+
rack (>= 0.9.0)
35+
binding_of_caller (0.7.2)
36+
debug_inspector (>= 0.0.1)
3137
builder (3.2.2)
38+
byebug (4.0.5)
39+
columnize (= 0.9.0)
40+
coderay (1.1.0)
3241
coffee-rails (4.0.1)
3342
coffee-script (>= 2.2.0)
3443
railties (>= 4.0.0, < 5.0)
3544
coffee-script (2.4.1)
3645
coffee-script-source
3746
execjs
3847
coffee-script-source (1.9.1.1)
48+
columnize (0.9.0)
49+
debug_inspector (0.0.2)
3950
erubis (2.7.0)
4051
execjs (2.5.2)
4152
hike (1.2.3)
@@ -103,11 +114,19 @@ GEM
103114
uglifier (2.7.1)
104115
execjs (>= 0.3.0)
105116
json (>= 1.8.0)
117+
web-console (2.1.2)
118+
activemodel (>= 4.0)
119+
binding_of_caller (>= 0.7.2)
120+
railties (>= 4.0)
121+
sprockets-rails (>= 2.0, < 4.0)
106122

107123
PLATFORMS
108124
ruby
109125

110126
DEPENDENCIES
127+
better_errors
128+
binding_of_caller
129+
byebug
111130
coffee-rails (~> 4.0.0)
112131
jbuilder (~> 2.0)
113132
jquery-rails
@@ -118,3 +137,4 @@ DEPENDENCIES
118137
sqlite3
119138
turbolinks
120139
uglifier (>= 1.3.0)
140+
web-console (~> 2.0)

README.rdoc

-33
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,5 @@
11
== README
22

3-
This README would normally document whatever steps are necessary to get the
4-
application up and running.
5-
6-
Things you may want to cover:
7-
8-
* Ruby version
9-
10-
* System dependencies
11-
12-
* Configuration
13-
14-
* Database creation
15-
16-
* Database initialization
17-
18-
* How to run the test suite
19-
20-
* Services (job queues, cache servers, search engines, etc.)
21-
22-
* Deployment instructions
23-
24-
* ...
25-
26-
27-
Please feel free to use a different markup language if you do not plan to run
28-
<tt>rake doc:app</tt>.
29-
30-
313
Features
324

335
1. blog post (show, read, create, edit, delete)
@@ -47,8 +19,3 @@ User Stories
4719
5. As a user, I can edit or delete my own comment.
4820
6. As a user, I can search for a specific post.
4921
7. As a user, I see "x" posts per page.
50-
51-
52-
53-
54-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Place all the behaviors and hooks related to the matching controller here.
2+
# All this logic will automatically be available in application.js.
3+
# You can use CoffeeScript in this file: http://coffeescript.org/
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Place all the behaviors and hooks related to the matching controller here.
2+
# All this logic will automatically be available in application.js.
3+
# You can use CoffeeScript in this file: http://coffeescript.org/
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place all the styles related to the articles controller here.
2+
// They will automatically be included in application.css.
3+
// You can use Sass (SCSS) here: http://sass-lang.com/
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place all the styles related to the welcome controller here.
2+
// They will automatically be included in application.css.
3+
// You can use Sass (SCSS) here: http://sass-lang.com/
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
class ArticlesController < ApplicationController
2+
3+
# def index
4+
#end
5+
6+
def show
7+
@article = Article.find(params[:id])
8+
9+
end
10+
11+
12+
def new
13+
14+
end
15+
16+
# def edit
17+
# end
18+
19+
def create
20+
@article = Article.new(article_params)
21+
22+
@article.save
23+
redirect_to @article
24+
end
25+
26+
#def update
27+
#end
28+
29+
#def destroy
30+
#end
31+
32+
33+
private
34+
35+
def article_params
36+
params.require(:article).permit(:title, :text)
37+
end
38+
39+
40+
41+
end

app/controllers/welcome_controller.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class WelcomeController < ApplicationController
2+
def index
3+
end
4+
end

app/helpers/articles_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module ArticlesHelper
2+
end

app/helpers/welcome_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module WelcomeHelper
2+
end

app/models/article.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Article < ActiveRecord::Base
2+
end

app/views/articles/new.html.erb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<h1>New Article</h1>
2+
3+
<%= form_for :article, url: articles_path do |f| %>
4+
<p>
5+
<%= f.label :title %><br>
6+
<%= f.text_field :title %>
7+
</p>
8+
9+
<p>
10+
<%= f.label :text %><br>
11+
<%= f.text_area :text %>
12+
</p>
13+
14+
<p>
15+
<%= f.submit %>
16+
</p>
17+
<% end %>

app/views/articles/show.html.erb

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
<p>
3+
<strong>Title:</strong>
4+
<%= @article.title %>
5+
</p>
6+
7+
<p>
8+
<strong>Text:</strong>
9+
<%= @article.text %>
10+
</p>

app/views/layouts/application.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</head>
99
<body>
1010

11+
1112
<%= yield %>
1213

1314
</body>

app/views/welcome/index.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Hello, Rails!</h1>

config/routes.rb

+5-54
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,7 @@
11
Rails.application.routes.draw do
2-
# The priority is based upon order of creation: first created -> highest priority.
3-
# See how all your routes lay out with "rake routes".
4-
5-
# You can have the root of your site routed with "root"
6-
# root 'welcome#index'
7-
8-
# Example of regular route:
9-
# get 'products/:id' => 'catalog#view'
10-
11-
# Example of named route that can be invoked with purchase_url(id: product.id)
12-
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
13-
14-
# Example resource route (maps HTTP verbs to controller actions automatically):
15-
# resources :products
16-
17-
# Example resource route with options:
18-
# resources :products do
19-
# member do
20-
# get 'short'
21-
# post 'toggle'
22-
# end
23-
#
24-
# collection do
25-
# get 'sold'
26-
# end
27-
# end
28-
29-
# Example resource route with sub-resources:
30-
# resources :products do
31-
# resources :comments, :sales
32-
# resource :seller
33-
# end
34-
35-
# Example resource route with more complex sub-resources:
36-
# resources :products do
37-
# resources :comments
38-
# resources :sales do
39-
# get 'recent', on: :collection
40-
# end
41-
# end
42-
43-
# Example resource route with concerns:
44-
# concern :toggleable do
45-
# post 'toggle'
46-
# end
47-
# resources :posts, concerns: :toggleable
48-
# resources :photos, concerns: :toggleable
49-
50-
# Example resource route within a namespace:
51-
# namespace :admin do
52-
# # Directs /admin/products/* to Admin::ProductsController
53-
# # (app/controllers/admin/products_controller.rb)
54-
# resources :products
55-
# end
2+
3+
resources :articles
4+
5+
root 'welcome#index'
6+
567
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateArticles < ActiveRecord::Migration
2+
def change
3+
create_table :articles do |t|
4+
t.string :title
5+
t.text :text
6+
7+
t.timestamps
8+
end
9+
end
10+
end

db/schema.rb

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# encoding: UTF-8
2+
# This file is auto-generated from the current state of the database. Instead
3+
# of editing this file, please use the migrations feature of Active Record to
4+
# incrementally modify your database, and then regenerate this schema definition.
5+
#
6+
# Note that this schema.rb definition is the authoritative source for your
7+
# database schema. If you need to create the application database on another
8+
# system, you should be using db:schema:load, not running all the migrations
9+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
10+
# you'll amass, the slower it'll run and the greater likelihood for issues).
11+
#
12+
# It's strongly recommended that you check this file into your version control system.
13+
14+
ActiveRecord::Schema.define(version: 20150426154437) do
15+
16+
create_table "articles", force: true do |t|
17+
t.string "title"
18+
t.text "text"
19+
t.datetime "created_at"
20+
t.datetime "updated_at"
21+
end
22+
23+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3470
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test_helper'
2+
3+
class ArticlesControllerTest < ActionController::TestCase
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'test_helper'
2+
3+
class WelcomeControllerTest < ActionController::TestCase
4+
test "should get index" do
5+
get :index
6+
assert_response :success
7+
end
8+
9+
end

test/fixtures/articles.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2+
3+
one:
4+
title: MyString
5+
text: MyText
6+
7+
two:
8+
title: MyString
9+
text: MyText

test/helpers/articles_helper_test.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require 'test_helper'
2+
3+
class ArticlesHelperTest < ActionView::TestCase
4+
end

test/helpers/welcome_helper_test.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require 'test_helper'
2+
3+
class WelcomeHelperTest < ActionView::TestCase
4+
end

test/models/article_test.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test_helper'
2+
3+
class ArticleTest < ActiveSupport::TestCase
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

0 commit comments

Comments
 (0)