-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
233e94c
commit e587bb6
Showing
35 changed files
with
729 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
class BlogsController < ApplicationController | ||
before_action :set_blog, only: %i[ show edit update destroy ] | ||
|
||
# GET /blogs or /blogs.json | ||
def index | ||
@blogs = Blog.all | ||
end | ||
|
||
# GET /blogs/1 or /blogs/1.json | ||
def show | ||
end | ||
|
||
# GET /blogs/new | ||
def new | ||
@blog = Blog.new | ||
end | ||
|
||
# GET /blogs/1/edit | ||
def edit | ||
end | ||
|
||
# POST /blogs or /blogs.json | ||
def create | ||
@blog = Blog.new(blog_params) | ||
|
||
respond_to do |format| | ||
if @blog.save | ||
format.html { redirect_to blog_url(@blog), notice: "Blog was successfully created." } | ||
format.json { render :show, status: :created, location: @blog } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
format.json { render json: @blog.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /blogs/1 or /blogs/1.json | ||
def update | ||
respond_to do |format| | ||
if @blog.update(blog_params) | ||
format.html { redirect_to blog_url(@blog), notice: "Blog was successfully updated." } | ||
format.json { render :show, status: :ok, location: @blog } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @blog.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /blogs/1 or /blogs/1.json | ||
def destroy | ||
@blog.destroy! | ||
|
||
respond_to do |format| | ||
format.html { redirect_to blogs_url, notice: "Blog was successfully destroyed." } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_blog | ||
@blog = Blog.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def blog_params | ||
params.require(:blog).permit(:title, :body, :user_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module BlogsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Blog < ApplicationRecord | ||
belongs_to :user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class User < ApplicationRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div id="<%= dom_id blog %>"> | ||
<p> | ||
<strong>Title:</strong> | ||
<%= blog.title %> | ||
</p> | ||
|
||
<p> | ||
<strong>Body:</strong> | ||
<%= blog.body %> | ||
</p> | ||
|
||
<p> | ||
<strong>User:</strong> | ||
<%= blog.user_id %> | ||
</p> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
json.extract! blog, :id, :title, :body, :user_id, :created_at, :updated_at | ||
json.url blog_url(blog, format: :json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<%= form_with(model: blog) do |form| %> | ||
<% if blog.errors.any? %> | ||
<div style="color: red"> | ||
<h2><%= pluralize(blog.errors.count, "error") %> prohibited this blog from being saved:</h2> | ||
|
||
<ul> | ||
<% blog.errors.each do |error| %> | ||
<li><%= error.full_message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div> | ||
<%= form.label :title, style: "display: block" %> | ||
<%= form.text_field :title %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :body, style: "display: block" %> | ||
<%= form.text_area :body %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :user_id, style: "display: block" %> | ||
<%= form.text_field :user_id %> | ||
</div> | ||
|
||
<div> | ||
<%= form.submit %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h1>Editing blog</h1> | ||
|
||
<%= render "form", blog: @blog %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Show this blog", @blog %> | | ||
<%= link_to "Back to blogs", blogs_path %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<p style="color: green"><%= notice %></p> | ||
|
||
<h1>Blogs</h1> | ||
|
||
<div id="blogs"> | ||
<% @blogs.each do |blog| %> | ||
<%= render blog %> | ||
<p> | ||
<%= link_to "Show this blog", blog %> | ||
</p> | ||
<% end %> | ||
</div> | ||
|
||
<%= link_to "New blog", new_blog_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.array! @blogs, partial: "blogs/blog", as: :blog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<h1>New blog</h1> | ||
|
||
<%= render "form", blog: @blog %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Back to blogs", blogs_path %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<p style="color: green"><%= notice %></p> | ||
|
||
<%= render @blog %> | ||
|
||
<div> | ||
<%= link_to "Edit this blog", edit_blog_path(@blog) %> | | ||
<%= link_to "Back to blogs", blogs_path %> | ||
<%= button_to "Destroy this blog", @blog, method: :delete %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial! "blogs/blog", blog: @blog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.