课程实训
This commit is contained in:
parent
a1ac008f45
commit
e6a3d8d455
|
|
@ -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://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the subject controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
class SubjectController < ApplicationController
|
||||
|
||||
def index
|
||||
@order = "created_at"
|
||||
@sort = "desc"
|
||||
search = params[:search]
|
||||
@subjects = Subject.where("name like ?", "%#{search}%").reorder("created_at desc")
|
||||
@subjects_count = @subjects.count
|
||||
@limit = 16
|
||||
@is_remote = true
|
||||
@subject_pages = Paginator.new @subjects_count, @limit, params['page'] || 1
|
||||
@offset ||= @subject_pages.offset
|
||||
@subjects = paginateHelper @subjects, @limit
|
||||
render :layout => "base_edu"
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
module SubjectHelper
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class Subject < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :course_list
|
||||
attr_accessible :description, :name, :status, :visits, :user_id, :course_list_id
|
||||
end
|
||||
|
|
@ -131,6 +131,8 @@ class User < Principal
|
|||
has_many :shixun_members, :dependent => :destroy
|
||||
has_many :challenges, :dependent => :destroy
|
||||
|
||||
has_many :subjects
|
||||
|
||||
has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
|
||||
:after_remove => Proc.new {|user, group| group.user_removed(user)}
|
||||
has_many :changesets, :dependent => :nullify
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
class CreateSubjects < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :subjects do |t|
|
||||
t.string :name
|
||||
t.text :description
|
||||
t.references :user
|
||||
t.references :course_list
|
||||
t.integer :visits
|
||||
t.integer :status
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
add_index :subjects, :user_id
|
||||
add_index :subjects, :course_list_id
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SubjectController, :type => :controller do
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
FactoryGirl.define do
|
||||
factory :subject do
|
||||
name "MyString"
|
||||
description "MyText"
|
||||
user nil
|
||||
course_list nil
|
||||
visits 1
|
||||
status 1
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Subject, :type => :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
Loading…
Reference in New Issue