Description:
moved to ror 2.0.2, add user rel to model submission
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@3 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r1:82d71b81c3b0 - - 7 files changed: 5 inserted, 10 deleted
@@ -1,41 +1,39 | |||
|
1 | 1 | class ProblemsController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate, :authorization |
|
4 | 4 | |
|
5 | 5 | def index |
|
6 | 6 | list |
|
7 | 7 | render :action => 'list' |
|
8 | 8 | end |
|
9 | 9 | |
|
10 | 10 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
11 | 11 | verify :method => :post, :only => [ :destroy, :create, :update ], |
|
12 | 12 | :redirect_to => { :action => :list } |
|
13 | 13 | |
|
14 | 14 | def list |
|
15 | - @problem_pages, @problems = paginate(:problems, | |
|
16 | - :per_page => 10, | |
|
17 | - :order => 'date_added DESC') | |
|
15 | + @problems = Problem.find(:all, :order => 'date_added DESC') | |
|
18 | 16 | end |
|
19 | 17 | |
|
20 | 18 | def show |
|
21 | 19 | @problem = Problem.find(params[:id]) |
|
22 | 20 | end |
|
23 | 21 | |
|
24 | 22 | def new |
|
25 | 23 | @problem = Problem.new |
|
26 | 24 | end |
|
27 | 25 | |
|
28 | 26 | def create |
|
29 | 27 | @problem = Problem.new(params[:problem]) |
|
30 | 28 | if @problem.save |
|
31 | 29 | flash[:notice] = 'Problem was successfully created.' |
|
32 | 30 | redirect_to :action => 'list' |
|
33 | 31 | else |
|
34 | 32 | render :action => 'new' |
|
35 | 33 | end |
|
36 | 34 | end |
|
37 | 35 | |
|
38 | 36 | def edit |
|
39 | 37 | @problem = Problem.find(params[:id]) |
|
40 | 38 | end |
|
41 | 39 |
@@ -1,39 +1,39 | |||
|
1 | 1 | class UserAdminController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate, :authorization |
|
4 | 4 | |
|
5 | 5 | def index |
|
6 | 6 | list |
|
7 | 7 | render :action => 'list' |
|
8 | 8 | end |
|
9 | 9 | |
|
10 | 10 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
11 | 11 | verify :method => :post, :only => [ :destroy, :create, :update ], |
|
12 | 12 | :redirect_to => { :action => :list } |
|
13 | 13 | |
|
14 | 14 | def list |
|
15 | - @user_pages, @users = paginate :users, :per_page => 50 | |
|
15 | + @users = User.find(:all) | |
|
16 | 16 | end |
|
17 | 17 | |
|
18 | 18 | def show |
|
19 | 19 | @user = User.find(params[:id]) |
|
20 | 20 | end |
|
21 | 21 | |
|
22 | 22 | def new |
|
23 | 23 | @user = User.new |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | def create |
|
27 | 27 | @user = User.new(params[:user]) |
|
28 | 28 | if @user.save |
|
29 | 29 | flash[:notice] = 'User was successfully created.' |
|
30 | 30 | redirect_to :action => 'list' |
|
31 | 31 | else |
|
32 | 32 | render :action => 'new' |
|
33 | 33 | end |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def edit |
|
37 | 37 | @user = User.find(params[:id]) |
|
38 | 38 | end |
|
39 | 39 |
@@ -1,28 +1,29 | |||
|
1 | 1 | class Submission < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | belongs_to :language |
|
4 | 4 | belongs_to :problem |
|
5 | + belongs_to :user | |
|
5 | 6 | |
|
6 | 7 | def self.find_by_user_and_problem(user_id, problem_id) |
|
7 | 8 | subcount = count(:conditions => "user_id = #{user_id} AND problem_id = #{problem_id}") |
|
8 | 9 | if subcount != 0 |
|
9 | 10 | last_sub = find(:first, |
|
10 | 11 | :conditions => {:user_id => user_id, |
|
11 | 12 | :problem_id => problem_id}, |
|
12 | 13 | :order => 'submitted_at DESC') |
|
13 | 14 | else |
|
14 | 15 | last_sub = nil |
|
15 | 16 | end |
|
16 | 17 | return subcount, last_sub |
|
17 | 18 | end |
|
18 | 19 | |
|
19 | 20 | def self.find_last_by_problem(problem_id) |
|
20 | 21 | # need to put in SQL command, maybe there's a better way |
|
21 | 22 | Submission.find_by_sql("SELECT * FROM submissions " + |
|
22 | 23 | "WHERE id = " + |
|
23 | 24 | "(SELECT MAX(id) FROM submissions AS subs " + |
|
24 | 25 | "WHERE subs.user_id = submissions.user_id AND " + |
|
25 | 26 | "problem_id = " + problem_id.to_s + " " + |
|
26 | 27 | "GROUP BY user_id)") |
|
27 | 28 | end |
|
28 | 29 |
@@ -4,30 +4,28 | |||
|
4 | 4 | <%= link_to 'Main', :controller => 'main', :action => 'list' %> |
|
5 | 5 | </div> |
|
6 | 6 | |
|
7 | 7 | <table> |
|
8 | 8 | <tr> |
|
9 | 9 | <% for column in Problem.content_columns %> |
|
10 | 10 | <th><%= column.human_name %></th> |
|
11 | 11 | <% end %> |
|
12 | 12 | </tr> |
|
13 | 13 | |
|
14 | 14 | <% for problem in @problems %> |
|
15 | 15 | <tr> |
|
16 | 16 | <% for column in Problem.content_columns %> |
|
17 | 17 | <td><%=h problem.send(column.name) %></td> |
|
18 | 18 | <% end %> |
|
19 | 19 | <td><%= link_to '[Toggle]', :action => 'toggle_avail', :id => problem.id %></td> |
|
20 | 20 | <td><%= link_to '[Stat]', :action => 'stat', :id => problem.id %></td> |
|
21 | 21 | <td><%= link_to '[Show]', :action => 'show', :id => problem %></td> |
|
22 | 22 | <td><%= link_to '[Edit]', :action => 'edit', :id => problem %></td> |
|
23 | 23 | <td><%= link_to '[Destroy]', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :post %></td> |
|
24 | 24 | </tr> |
|
25 | 25 | <% end %> |
|
26 | 26 | </table> |
|
27 | 27 | |
|
28 | - <%= link_to 'Previous page', { :page => @problem_pages.current.previous } if @problem_pages.current.previous %> | |
|
29 | - <%= link_to 'Next page', { :page => @problem_pages.current.next } if @problem_pages.current.next %> | |
|
30 | 28 | |
|
31 | 29 | <br /> |
|
32 | 30 | |
|
33 | 31 | <%= link_to 'New problem', :action => 'new' %> |
@@ -26,30 +26,28 | |||
|
26 | 26 | </tr></table> |
|
27 | 27 | <% end %> |
|
28 | 28 | |
|
29 | 29 | </div> |
|
30 | 30 | |
|
31 | 31 | <table> |
|
32 | 32 | <tr> |
|
33 | 33 | <% for column in User.content_columns %> |
|
34 | 34 | <th><%= column.human_name %></th> |
|
35 | 35 | <% end %> |
|
36 | 36 | </tr> |
|
37 | 37 | |
|
38 | 38 | <% for user in @users %> |
|
39 | 39 | <tr> |
|
40 | 40 | <% for column in User.content_columns %> |
|
41 | 41 | <td><%=h user.send(column.name) %></td> |
|
42 | 42 | <% end %> |
|
43 | 43 | <td><%= link_to 'Show', :action => 'show', :id => user %></td> |
|
44 | 44 | <td><%= link_to 'Edit', :action => 'edit', :id => user %></td> |
|
45 | 45 | <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td> |
|
46 | 46 | </tr> |
|
47 | 47 | <% end %> |
|
48 | 48 | </table> |
|
49 | 49 | |
|
50 | - <%= link_to 'Previous page', { :page => @user_pages.current.previous } if @user_pages.current.previous %> | |
|
51 | - <%= link_to 'Next page', { :page => @user_pages.current.next } if @user_pages.current.next %> | |
|
52 | 50 | |
|
53 | 51 | <br /> |
|
54 | 52 | |
|
55 | 53 | <%= link_to 'New user', :action => 'new' %> |
@@ -1,32 +1,32 | |||
|
1 | 1 | # Be sure to restart your web server when you modify this file. |
|
2 | 2 | |
|
3 | 3 | # Uncomment below to force Rails into production mode when |
|
4 | 4 | # you don't control web/app server and can't set it the proper way |
|
5 | 5 | # ENV['RAILS_ENV'] ||= 'production' |
|
6 | 6 | |
|
7 | 7 | # Specifies gem version of Rails to use when vendor/rails is not present |
|
8 |
- RAILS_GEM_VERSION = ' |
|
|
8 | + RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION | |
|
9 | 9 | |
|
10 | 10 | # Bootstrap the Rails environment, frameworks, and default configuration |
|
11 | 11 | require File.join(File.dirname(__FILE__), 'boot') |
|
12 | 12 | |
|
13 | 13 | Rails::Initializer.run do |config| |
|
14 | 14 | # Settings in config/environments/* take precedence over those specified here |
|
15 | 15 | |
|
16 | 16 | # Skip frameworks you're not going to use (only works if using vendor/rails) |
|
17 | 17 | # config.frameworks -= [ :action_web_service, :action_mailer ] |
|
18 | 18 | |
|
19 | 19 | # Only load the plugins named here, by default all plugins in vendor/plugins are loaded |
|
20 | 20 | # config.plugins = %W( exception_notification ssl_requirement ) |
|
21 | 21 | |
|
22 | 22 | # Add additional load paths for your own custom dirs |
|
23 | 23 | # config.load_paths += %W( #{RAILS_ROOT}/extras ) |
|
24 | 24 | |
|
25 | 25 | # Force all environments to use the same logger level |
|
26 | 26 | # (by default production uses :info, the others :debug) |
|
27 | 27 | # config.log_level = :debug |
|
28 | 28 | |
|
29 | 29 | # Use the database for sessions instead of the file system |
|
30 | 30 | # (create the session table with 'rake db:sessions:create') |
|
31 | 31 | config.action_controller.session_store = :active_record_store |
|
32 | 32 |
@@ -1,21 +1,21 | |||
|
1 | 1 | # Settings specified here will take precedence over those in config/environment.rb |
|
2 | 2 | |
|
3 | 3 | # In the development environment your application's code is reloaded on |
|
4 | 4 | # every request. This slows down response time but is perfect for development |
|
5 | 5 | # since you don't have to restart the webserver when you make code changes. |
|
6 | 6 | config.cache_classes = false |
|
7 | 7 | |
|
8 | 8 | # Log error messages when you accidentally call methods on nil. |
|
9 | 9 | config.whiny_nils = true |
|
10 | 10 | |
|
11 | 11 | # Enable the breakpoint server that script/breakpointer connects to |
|
12 | - config.breakpoint_server = true | |
|
12 | + #config.breakpoint_server = true | |
|
13 | 13 | |
|
14 | 14 | # Show full error reports and disable caching |
|
15 | 15 | config.action_controller.consider_all_requests_local = true |
|
16 | 16 | config.action_controller.perform_caching = false |
|
17 | 17 | config.action_view.cache_template_extensions = false |
|
18 | 18 | config.action_view.debug_rjs = true |
|
19 | 19 | |
|
20 | 20 | # Don't care if the mailer can't send |
|
21 | 21 | config.action_mailer.raise_delivery_errors = false |
You need to be logged in to leave comments.
Login now