Skip to content
This repository was archived by the owner on Nov 13, 2020. It is now read-only.

Commit a3cb5c1

Browse files
committed
Adding default scaffold controllers.
Right now, they're all bespoke. We'll change that.
1 parent ae1a880 commit a3cb5c1

File tree

4 files changed

+147
-3
lines changed

4 files changed

+147
-3
lines changed

app/controllers/bespoke_controller.rb

+48
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,50 @@
11
class BespokeController < ApplicationController
2+
# GET /posts
3+
# GET /posts.json
4+
def index
5+
@posts = Post.all
6+
7+
render json: @posts
8+
end
9+
10+
# GET /posts/1
11+
# GET /posts/1.json
12+
def show
13+
@post = Post.find(params[:id])
14+
15+
render json: @post
16+
end
17+
18+
# POST /posts
19+
# POST /posts.json
20+
def create
21+
@post = Post.new(params[:post])
22+
23+
if @post.save
24+
render json: @post, status: :created, location: @post
25+
else
26+
render json: @post.errors, status: :unprocessable_entity
27+
end
28+
end
29+
30+
# PATCH/PUT /posts/1
31+
# PATCH/PUT /posts/1.json
32+
def update
33+
@post = Post.find(params[:id])
34+
35+
if @post.update(params[:post])
36+
head :no_content
37+
else
38+
render json: @post.errors, status: :unprocessable_entity
39+
end
40+
end
41+
42+
# DELETE /posts/1
43+
# DELETE /posts/1.json
44+
def destroy
45+
@post = Post.find(params[:id])
46+
@post.destroy
47+
48+
head :no_content
49+
end
250
end

app/controllers/idstyle_controller.rb

+48
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,50 @@
11
class IdstyleController < ApplicationController
2+
# GET /posts
3+
# GET /posts.json
4+
def index
5+
@posts = Post.all
6+
7+
render json: @posts
8+
end
9+
10+
# GET /posts/1
11+
# GET /posts/1.json
12+
def show
13+
@post = Post.find(params[:id])
14+
15+
render json: @post
16+
end
17+
18+
# POST /posts
19+
# POST /posts.json
20+
def create
21+
@post = Post.new(params[:post])
22+
23+
if @post.save
24+
render json: @post, status: :created, location: @post
25+
else
26+
render json: @post.errors, status: :unprocessable_entity
27+
end
28+
end
29+
30+
# PATCH/PUT /posts/1
31+
# PATCH/PUT /posts/1.json
32+
def update
33+
@post = Post.find(params[:id])
34+
35+
if @post.update(params[:post])
36+
head :no_content
37+
else
38+
render json: @post.errors, status: :unprocessable_entity
39+
end
40+
end
41+
42+
# DELETE /posts/1
43+
# DELETE /posts/1.json
44+
def destroy
45+
@post = Post.find(params[:id])
46+
@post.destroy
47+
48+
head :no_content
49+
end
250
end
+48
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,50 @@
11
class UrlstyleController < ApplicationController
2+
# GET /posts
3+
# GET /posts.json
4+
def index
5+
@posts = Post.all
6+
7+
render json: @posts
8+
end
9+
10+
# GET /posts/1
11+
# GET /posts/1.json
12+
def show
13+
@post = Post.find(params[:id])
14+
15+
render json: @post
16+
end
17+
18+
# POST /posts
19+
# POST /posts.json
20+
def create
21+
@post = Post.new(params[:post])
22+
23+
if @post.save
24+
render json: @post, status: :created, location: @post
25+
else
26+
render json: @post.errors, status: :unprocessable_entity
27+
end
28+
end
29+
30+
# PATCH/PUT /posts/1
31+
# PATCH/PUT /posts/1.json
32+
def update
33+
@post = Post.find(params[:id])
34+
35+
if @post.update(params[:post])
36+
head :no_content
37+
else
38+
render json: @post.errors, status: :unprocessable_entity
39+
end
40+
end
41+
42+
# DELETE /posts/1
43+
# DELETE /posts/1.json
44+
def destroy
45+
@post = Post.find(params[:id])
46+
@post.destroy
47+
48+
head :no_content
49+
end
250
end

config/routes.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
root "homepage#index"
33

44
namespace "bespoke" do
5-
resources :posts
5+
resources :posts, except: [:new, :edit]
66
end
77

88
namespace "idstyle" do
9-
resources :posts
9+
resources :posts, except: [:new, :edit]
1010
end
1111

1212
namespace "urlstyle" do
13-
resources :posts
13+
resources :posts, except: [:new, :edit]
1414
end
1515
end

0 commit comments

Comments
 (0)