Skip to content

Commit

Permalink
And join table
Browse files Browse the repository at this point in the history
  • Loading branch information
YujiaY committed Mar 28, 2017
1 parent 119df5d commit 2256fd3
Show file tree
Hide file tree
Showing 59 changed files with 846 additions and 1 deletion.
Binary file added @errors.docx
Binary file not shown.
Empty file added @frame.txt
Empty file.
3 changes: 3 additions & 0 deletions app/assets/javascripts/contents.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/courses.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/users.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/contents.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Contents controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/courses.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Courses controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
89 changes: 89 additions & 0 deletions app/assets/stylesheets/scaffolds.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
margin: 33px;
}

p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
margin: 33px;
}

pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}

a {
color: #000;

&:visited {
color: #666;
}

&:hover {
color: #fff;
background-color: #000;
}
}

th {
padding-bottom: 5px;
}

td {
padding-bottom: 7px;
padding-left: 5px;
padding-right: 5px;
}

div {
&.field, &.actions {
margin-bottom: 10px;
}
}

#notice {
color: green;
}

.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}

#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;

h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0;
background-color: #c00;
color: #fff;
}

ul li {
font-size: 12px;
list-style: square;
}
}

label {
display: block;
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/users.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
74 changes: 74 additions & 0 deletions app/controllers/contents_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class ContentsController < ApplicationController
before_action :set_content, only: [:show, :edit, :update, :destroy]

# GET /contents
# GET /contents.json
def index
@contents = Content.all
end

# GET /contents/1
# GET /contents/1.json
def show
end

# GET /contents/new
def new
@content = Content.new
end

# GET /contents/1/edit
def edit
end

# POST /contents
# POST /contents.json
def create
@content = Content.new(content_params)

respond_to do |format|
if @content.save
format.html { redirect_to @content, notice: 'Content was successfully created.' }
format.json { render :show, status: :created, location: @content }
else
format.html { render :new }
format.json { render json: @content.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /contents/1
# PATCH/PUT /contents/1.json
def update
respond_to do |format|
if @content.update(content_params)
format.html { redirect_to @content, notice: 'Content was successfully updated.' }
format.json { render :show, status: :ok, location: @content }
else
format.html { render :edit }
format.json { render json: @content.errors, status: :unprocessable_entity }
end
end
end

# DELETE /contents/1
# DELETE /contents/1.json
def destroy
@content.destroy
respond_to do |format|
format.html { redirect_to contents_url, notice: 'Content was successfully destroyed.' }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_content
@content = Content.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def content_params
params.require(:content).permit(:name)
end
end
74 changes: 74 additions & 0 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class CoursesController < ApplicationController
before_action :set_course, only: [:show, :edit, :update, :destroy]

# GET /courses
# GET /courses.json
def index
@courses = Course.all
end

# GET /courses/1
# GET /courses/1.json
def show
end

# GET /courses/new
def new
@course = Course.new
end

# GET /courses/1/edit
def edit
end

# POST /courses
# POST /courses.json
def create
@course = Course.new(course_params)

respond_to do |format|
if @course.save
format.html { redirect_to @course, notice: 'Course was successfully created.' }
format.json { render :show, status: :created, location: @course }
else
format.html { render :new }
format.json { render json: @course.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /courses/1
# PATCH/PUT /courses/1.json
def update
respond_to do |format|
if @course.update(course_params)
format.html { redirect_to @course, notice: 'Course was successfully updated.' }
format.json { render :show, status: :ok, location: @course }
else
format.html { render :edit }
format.json { render json: @course.errors, status: :unprocessable_entity }
end
end
end

# DELETE /courses/1
# DELETE /courses/1.json
def destroy
@course.destroy
respond_to do |format|
format.html { redirect_to courses_url, notice: 'Course was successfully destroyed.' }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_course
@course = Course.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def course_params
params.require(:course).permit(:name)
end
end
74 changes: 74 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]

# GET /users
# GET /users.json
def index
@users = User.all
end

# GET /users/1
# GET /users/1.json
def show
end

# GET /users/new
def new
@user = User.new
end

# GET /users/1/edit
def edit
end

# POST /users
# POST /users.json
def create
@user = User.new(user_params)

respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /users/1
# PATCH/PUT /users/1.json
def update
respond_to do |format|
if @user.update(user_params)
format.html { redirect_to @user, notice: 'User was successfully updated.' }
format.json { render :show, status: :ok, location: @user }
else
format.html { render :edit }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end

# DELETE /users/1
# DELETE /users/1.json
def destroy
@user.destroy
respond_to do |format|
format.html { redirect_to users_url, notice: 'User was successfully destroyed.' }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:name)
end
end
2 changes: 2 additions & 0 deletions app/helpers/contents_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ContentsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/courses_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CoursesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UsersHelper
end
3 changes: 3 additions & 0 deletions app/models/content.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Content < ApplicationRecord
has_and_belongs_to_many :courses
end
4 changes: 4 additions & 0 deletions app/models/course.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Course < ApplicationRecord
has_and_belongs_to_many :users
has_and_belongs_to_many :contents
end
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class User < ApplicationRecord
has_and_belongs_to_many :courses
end
2 changes: 2 additions & 0 deletions app/views/contents/_content.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! content, :id, :name, :created_at, :updated_at
json.url content_url(content, format: :json)
22 changes: 22 additions & 0 deletions app/views/contents/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%= form_for(content) do |f| %>
<% if content.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(content.errors.count, "error") %> prohibited this content from being saved:</h2>

<ul>
<% content.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>

<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/contents/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing Content</h1>

<%= render 'form', content: @content %>
<%= link_to 'Show', @content %> |
<%= link_to 'Back', contents_path %>
Loading

0 comments on commit 2256fd3

Please sign in to comment.