diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -47,6 +47,23 @@ end end + def quick_create + @problem = Problem.new(params[:problem]) + @problem.full_name = @problem.name if @problem.full_name == '' + @problem.full_score = 100 + @problem.available = false + @problem.test_allowed = true + @problem.output_only = false + @problem.date_added = Time.new + if @problem.save + flash[:notice] = 'Problem was successfully created.' + redirect_to :action => 'list' + else + flash[:notice] = 'Error saving problem' + redirect_to :action => 'list' + end + end + def edit @problem = Problem.find(params[:id]) @description = @problem.description diff --git a/app/models/problem.rb b/app/models/problem.rb --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -2,6 +2,9 @@ belongs_to :description + validates_presence_of :name + validates_presence_of :full_name + def self.find_available_problems find(:all, :conditions => {:available => true}, :order => "date_added DESC") end diff --git a/app/views/problems/list.rhtml b/app/views/problems/list.rhtml --- a/app/views/problems/list.rhtml +++ b/app/views/problems/list.rhtml @@ -11,6 +11,17 @@ <%= link_to 'Turn on all problems', :action => 'turn_all_on' %>

+
+ <% form_tag :action => 'quick_create' do %> + Quick New: + + <%= text_field 'problem', 'name' %> | + + <%= text_field 'problem', 'full_name' %> + <%= submit_tag "Create" %> + <% end %> +
+
Name