-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from RailsGEnthusiasts/guides
Guides (issue #18)
- Loading branch information
Showing
33 changed files
with
559 additions
and
10 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
|
@@ -9,3 +9,5 @@ | |
@import "search"; | ||
@import "tags"; | ||
@import "vote"; | ||
@import "guide_categories"; | ||
@import "guides"; |
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,13 @@ | ||
.category-btn | ||
margin-right: 5px | ||
|
||
.dropdown | ||
display: inline-block | ||
|
||
.create-new-field | ||
padding: 0 | ||
padding-right: 5px | ||
display: inline-block | ||
|
||
.btn-new-category | ||
margin-top: 5px |
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,25 @@ | ||
.guide-nav | ||
padding-top: 10px | ||
|
||
.guide-xs | ||
display: inline-block | ||
|
||
.guide-nav a:hover | ||
background-color: #FF704D | ||
|
||
.guide-nav a:link | ||
font-size: 25px | ||
font-weight: bold | ||
color: #FFFFFF | ||
text-decoration: none | ||
text-shadow: 2px 2px #943327 | ||
|
||
.guide-nav a:visited | ||
color: #FFFFFF | ||
|
||
.guide-nav .text | ||
vertical-align: middle | ||
|
||
.show | ||
margin-top: 10px | ||
margin-right: 5px |
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,74 @@ | ||
class GuideCategoriesController < ApplicationController | ||
before_action :set_guide_category, only: [:show, :edit, :update, :destroy] | ||
|
||
# GET /guide_categories | ||
# GET /guide_categories.json | ||
def index | ||
@guide_categories = GuideCategory.all | ||
end | ||
|
||
# GET /guide_categories/1 | ||
# GET /guide_categories/1.json | ||
def show | ||
end | ||
|
||
# GET /guide_categories/new | ||
def new | ||
@guide_category = GuideCategory.new | ||
end | ||
|
||
# GET /guide_categories/1/edit | ||
def edit | ||
end | ||
|
||
# POST /guide_categories | ||
# POST /guide_categories.json | ||
def create | ||
@guide_category = GuideCategory.new(guide_category_params) | ||
|
||
respond_to do |format| | ||
if @guide_category.save | ||
format.html { redirect_to @guide_category, notice: 'Guide Category was successfully created.' } | ||
format.json { render action: 'show', status: :created, location: @guide_category } | ||
else | ||
format.html { render action: 'new' } | ||
format.json { render json: @guide_category.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /guide_categories/1 | ||
# PATCH/PUT /guide_categories/1.json | ||
def update | ||
respond_to do |format| | ||
if @guide_category.update(guide_category_params) | ||
format.html { redirect_to @guide_category, notice: 'guide category was successfully updated.' } | ||
format.json { head :no_content } | ||
else | ||
format.html { render action: 'edit' } | ||
format.json { render json: @guide_category.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /guide_categories/1 | ||
# DELETE /guide_categories/1.json | ||
def destroy | ||
@guide_category.destroy | ||
respond_to do |format| | ||
format.html { redirect_to guide_categories_url } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_guide_category | ||
@guide_category = GuideCategory.find(params[:id]) | ||
end | ||
|
||
# Never trust parameters from the scary internet, only allow the white list through. | ||
def guide_category_params | ||
params.require(:guide_category).permit(:name) | ||
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,97 @@ | ||
class GuidesController < ApplicationController | ||
before_action :set_guide, only: [:show, :edit, :update, :destroy] | ||
before_action :require_login, except: [:index, :show] | ||
|
||
# GET /guide | ||
# GET /guide.json | ||
def index | ||
@guide_categories = GuideCategory.all | ||
@guides = Guide.all | ||
end | ||
|
||
# GET /guide/1 | ||
# GET /guide/1.json | ||
def show | ||
@comment = Comment.new | ||
@comment.parent = @guide | ||
end | ||
|
||
# GET /guide/new | ||
def new | ||
@guide_categories = GuideCategory.all | ||
@guide = Guide.new(new_guide_params) | ||
end | ||
|
||
# GET /guide/1/edit | ||
def edit | ||
@guide_categories = GuideCategory.all | ||
end | ||
|
||
# POST /guide | ||
# POST /guide.json | ||
def create | ||
@guide_categories = GuideCategory.all | ||
@guide = Guide.new(guide_params) | ||
@guide.user = current_user | ||
|
||
respond_to do |format| | ||
if @guide.save | ||
format.html { redirect_to post_path(@guide), notice: 'Guide was successfully created.' } | ||
format.json { render action: 'show', status: :created, location: @guide } | ||
else | ||
format.html { render action: 'new' } | ||
format.json { render json: @guide.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /guide/1 | ||
# PATCH/PUT /guide/1.json | ||
def update | ||
authorize @guide | ||
respond_to do |format| | ||
if @guide.update(guide_params) | ||
format.html { redirect_to post_path(@guide), notice: 'Guide was successfully updated.' } | ||
format.json { head :no_content } | ||
else | ||
format.html { render action: 'edit' } | ||
format.json { render json: @guide.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /guide/1 | ||
# DELETE /guide/1.json | ||
def destroy | ||
@guide.destroy | ||
respond_to do |format| | ||
format.html { redirect_to guide | ||
_url } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_guide | ||
@guide = Guide.find(params[:id]) | ||
end | ||
|
||
def new_guide_params | ||
if params[:guide] | ||
{guide_category_id: params[:guide][:guide_category_id]} | ||
else | ||
{} | ||
end | ||
end | ||
|
||
# Never trust parameters from the scary internet, only allow the white list through. | ||
def guide_params | ||
params.require(:guide).permit( | ||
:guide_category_id, | ||
:body_markdown, | ||
:user_id, | ||
:title, | ||
:tags_string) | ||
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
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,4 @@ | ||
class Guide < InternalPost | ||
belongs_to :category, class_name: 'GuideCategory', foreign_key: "guide_category_id" | ||
validates_presence_of :category | ||
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,8 @@ | ||
class GuideCategory < ActiveRecord::Base | ||
has_many :guides | ||
validates :name, presence: true | ||
|
||
def add_category_index | ||
@guide = Guide.new | ||
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,11 @@ | ||
GuidePolicy = Struct.new(:user, :post) do | ||
def update? | ||
return false unless user | ||
user.admin? || post.user == user | ||
end | ||
|
||
def destroy? | ||
return false unless user | ||
user.admin? | ||
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,16 @@ | ||
<h1> | ||
Guide Categories | ||
<%= link_to 'New Guide', new_guide_path, class: 'btn btn-primary pull-right' %> | ||
</h1> | ||
|
||
<table class="guide-categories table"> | ||
<tbody> | ||
<% @guide_categories.each do |category| %> | ||
<tr> | ||
<td> | ||
<%= link_to category.name, category %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> |
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,20 @@ | ||
<%= form_for(@guide_category) do |f| %> | ||
<% if @guide_category.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@guide_category.errors.count, "error") %> prohibited this guide_category from being saved:</h2> | ||
|
||
<ul> | ||
<% @guide_category.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="form-group"> | ||
<%= f.label :name, "Category Name" %> | ||
<%= f.text_field :name, class: 'form-control input-lg' %> | ||
</div> | ||
|
||
<%= f.submit nil, class: 'btn btn-primary', value: 'Save Category' %> | ||
<% 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 @@ | ||
<h1> | ||
<%= @guide_category.name %> | ||
<%= link_to 'New Guide', new_guide_path('guide[guide_category_id]' => @guide_category.id), class: 'btn btn-primary pull-right' %> | ||
<%= link_to 'New Category', new_guide_category_path, class: 'btn btn-primary category-btn pull-right' %> | ||
</h1> | ||
|
||
<table class="guide-categories table"> | ||
<tbody> | ||
<% @guide_category.guides.each do |guide| %> | ||
<tr> | ||
<td> | ||
<%= link_to guide.title, guide %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> |
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,39 @@ | ||
<h1>Editing Guide</h1> | ||
|
||
<%= form_for(@guide, url: (@guide.new_record? ? guides_path : guide_path(@guide))) do |f| %> | ||
<% if @guide.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@guide.errors.count, "error") %> prohibited this guide from being saved:</h2> | ||
|
||
<ul> | ||
<% @guide.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="form-group"> | ||
<%= f.label :guide_category_id, 'Choose Category' %> | ||
<%= f.select :guide_category_id, @guide_categories.map { |gc| [gc.name, gc.id] }, {}, {class: 'form-control'} %> | ||
<%= link_to 'New Category', new_guide_category_path, class: 'btn btn-primary btn-xs btn-new-category' %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.label :title %> | ||
<%= f.text_field :title, class: 'form-control input-lg' %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.label :body_markdown %> | ||
<%= f.text_area :body_markdown, class: 'form-control', rows: 5 %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.label :tags_string, "Tags" %> | ||
<%= f.text_field :tags_string, class: 'form-control' %> | ||
</div> | ||
|
||
<%= f.submit nil, class: 'btn btn-default' %> | ||
<% end %> |
Oops, something went wrong.