Skip to content

Commit

Permalink
complete homework for blog with create and show blog
Browse files Browse the repository at this point in the history
  • Loading branch information
804035184 committed May 26, 2020
1 parent ae967f6 commit a8f5a50
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/controllers/blogs_controller.rb
Expand Up @@ -76,6 +76,7 @@ def show
blog = Blog.find(params[:id])
render_404 unless blog.classroom_id == params[:classroom_id].to_i
@scores = {:score1 => blog.score1,:score2 => blog.score2}
@homework = Homework.find(blog.homework)
#puts "----------------------------"
#puts blog
#puts blog.title
Expand All @@ -92,6 +93,7 @@ def show_raw
def create
classroom = Classroom.find(params[:classroom_id])
new_blog = params[:blog]
puts new_blog
type = 'blog'
if new_blog['file_name'] == 'daily_scrum.md'
type = 'daily_scrum'
Expand All @@ -103,6 +105,7 @@ def create
blog_record.user_id = user.id
blog_record.score1 = 0
blog_record.score2 = 0
blog_record.homework = new_blog['hw_id']
blog_record.save
redirect_to classroom_blogs_path
end
Expand Down
10 changes: 10 additions & 0 deletions app/javascript/packs/new_blog.js
Expand Up @@ -40,6 +40,7 @@ document.addEventListener('DOMContentLoaded', () => {
str_hw: '请选择作业',
homeworks: [],
containers: [],
containers1:[],
containerId: null,
hwId: null,
blog: null,
Expand Down Expand Up @@ -109,6 +110,12 @@ document.addEventListener('DOMContentLoaded', () => {
}
}
}
for (let homework of homeworks) {
this.containers1.push({
id: homework.id,
name: homework.name,
});
}
},
methods: {
createBlog() {
Expand Down Expand Up @@ -177,6 +184,9 @@ document.addEventListener('DOMContentLoaded', () => {
});
return res;
},
choosehomework(containers1){
this.blog.hw_id = containers1;
},
chooseContainer(container) {
if (this.type === 'blog') {
this.blog.project_id = container;
Expand Down
2 changes: 1 addition & 1 deletion app/views/blogs/new.html.haml
Expand Up @@ -13,7 +13,7 @@
%el-option{'v-for': '(container, index) in containers', ':label': 'container.name', ':value': 'container.id', ':key': 'index'}
%input{':value': 'blog.project_id', name: 'blog[project_id]', style: 'display: none'}
%el-form-item{label: '作业', 'prop': 'hw_id'}
%el-select{'v-model': 'hwId', ':placeholder': "str_hw"}
%el-select{'v-model': 'hwId', '@change': 'choosehomework',':placeholder': "str_hw"}
%el-option{'v-for': '(homework, index) in homeworks', ':label': 'homework.name', ':value': 'homework.id', ':key': 'index'}
%input{':value': 'blog.hw_id', name: 'blog[hw_id]', style: 'display: none'}
%el-form-item{label: '标题', 'prop': 'title'}
Expand Down
11 changes: 10 additions & 1 deletion app/views/blogs/show.html.haml
Expand Up @@ -6,12 +6,21 @@
#show-blog-app{data: {blog: current_blog, blogs: blogs_data, comments: comments_data}, 'v-loading': 'loading', 'element-loading-text': '加载中'}
.root.small-container{'v-if': 'blog'}
%el-container
%el-aside{width:'15%',style:"background-color: blue"}
%el-aside{width:'15%'}
%div
博客所属作业
%ul
%li=@homework[:name]
%ul
博客分数
%ul
%ul
score1
%li=@scores[:score1]
score2
%li=@scores[:score2]
%ul
%ul
%div{'v-if':'!blog.can_edit'}
%a.el-buttun{':href':"'#{classroom_path(id: params[:classroom_id])}' + '/blogs/' + blog.id + '/score'" } 评分
%el-main
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20200526140220_add_score1_to_blogs.rb
@@ -0,0 +1,5 @@
class AddScore1ToBlogs < ActiveRecord::Migration[5.2]
def change
add_column :blogs, :score1, :integer
end
end
5 changes: 5 additions & 0 deletions db/migrate/20200526140233_add_score2_to_blogs.rb
@@ -0,0 +1,5 @@
class AddScore2ToBlogs < ActiveRecord::Migration[5.2]
def change
add_column :blogs, :score2, :integer
end
end
5 changes: 5 additions & 0 deletions db/migrate/20200526140252_add_homework_to_blogs.rb
@@ -0,0 +1,5 @@
class AddHomeworkToBlogs < ActiveRecord::Migration[5.2]
def change
add_column :blogs, :homework, :integer
end
end
5 changes: 4 additions & 1 deletion db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_05_25_075405) do
ActiveRecord::Schema.define(version: 2020_05_26_140252) do

create_table "auto_test_projects", force: :cascade do |t|
t.datetime "created_at", null: false
Expand All @@ -30,6 +30,9 @@
t.integer "user_id"
t.integer "classroom_id"
t.string "blog_type"
t.integer "score1"
t.integer "score2"
t.integer "homework"
t.index ["classroom_id"], name: "index_blogs_on_classroom_id"
t.index ["user_id"], name: "index_blogs_on_user_id"
end
Expand Down

0 comments on commit a8f5a50

Please sign in to comment.