Skip to content
Browse files

Admin required to modify the course

  • Loading branch information...
1 parent 42d69ef commit c3611a7b726b6fd70452e172b240ce9b6fa41179 @hanjianwei hanjianwei committed
View
6 app/controllers/application_controller.rb
@@ -3,6 +3,12 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+ def admin_user
+ unless current_user.admin?
+ redirect_back_or_to root_url, :alert => "你不是管理员!"
+ end
+ end
+
private
def not_authenticated
redirect_to login_url, :alert => "请先登录!"
View
3 app/controllers/chapters_controller.rb
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
class ChaptersController < ApplicationController
+ before_filter :require_login, :only => [:new, :create, :edit, :update, :sort]
+ before_filter :admin_user, :only => [:new, :create, :edit, :update, :sort]
+
def new
@course = Course.find(params[:course_id])
@chapter = @course.chapters.new
View
3 app/controllers/courses_controller.rb
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
class CoursesController < ApplicationController
+ before_filter :require_login, :only => [:new, :create, :edit, :update]
+ before_filter :admin_user, :only => [:new, :create, :edit, :update]
+
def index
@courses = Course.all
end
View
6 app/controllers/users_controller.rb
@@ -69,10 +69,4 @@ def correct_user
redirect_back_or_to root_url, :alert => "你没有编辑该账号的权限!"
end
end
-
- def admin_user
- unless current_user.admin?
- redirect_back_or_to root_url, :alert => "你不是管理员!"
- end
- end
end
View
3 app/views/chapters/show.html.erb
@@ -2,5 +2,4 @@
<%= markdown @chapter.content %>
-<a class="btn btn-danger" href="<%= edit_course_chapter_path(@course, @chapter) %>">编辑信息</a>
-<a class="btn btn-primary" href="<%= courses_path(@course) %>">返回课程</a>
+<% render 'courses/sidebar' %>
View
9 app/views/courses/_sidebar.html.erb
@@ -0,0 +1,9 @@
+<% content_for :sidebar do %>
+ <h3><%= link_to @course.name, course_path(@course) %></h3>
+ <ul class="nav nav-list">
+ <li class="nav-header"><i class="icon-book"></i>目录</li>
+ <% @course.chapters.each do |chapter| %>
+ <li><%= link_to chapter.title, course_chapter_path(@course, chapter) %></li>
+ <% end %>
+ </ul>
+<% end %>
View
2 app/views/courses/show.html.erb
@@ -11,3 +11,5 @@
<a class="btn btn-danger" href="<%= edit_course_path(@course) %>">编辑信息</a>
</div>
</form>
+
+<%= render :partial => 'sidebar' %>
View
8 app/views/home/index.html.erb
@@ -3,12 +3,10 @@
<%= render 'shared/flash_messages' %>
<% content_for :sidebar do %>
- <h3>导航</h3>
+ <h3>你要找什么?</h3>
<ul class="nav nav-list">
- <li class="nav-header">Sidebar</li>
- <li><%= link_to "Link1", "/path1" %></li>
- <li><%= link_to "Link2", "/path2" %></li>
- <li><%= link_to "Link3", "/path3" %></li>
+ <li class="nav-header">课程</li>
+ <li><%= link_to "数据结构", '/courses/1' %></li>
</ul>
<% end %>
View
5 app/views/layouts/application.html.erb
@@ -34,7 +34,10 @@
<%= link_to 'Edo', root_url, :class => 'brand' %>
<div class="container nav-collapse">
<ul class="nav">
- <li><%= link_to "课程列表", courses_path %></li>
+ <li><%= link_to "课程", courses_path %></li>
+ <li><%= link_to "问题", courses_path %></li>
+ <li><%= link_to "找老师", 'mailto: hanjianwei@mail.zjgsu.edu.cn' %></li>
+ <li><%= link_to "关于本站", '#' %></li>
</ul>
<ul class="nav pull-right">
<% if current_user %>

0 comments on commit c3611a7

Please sign in to comment.
Something went wrong with that request. Please try again.