diff --git a/app/assets/javascripts/problems.js.coffee b/app/assets/javascripts/problems.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/problems.js.coffee @@ -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://coffeescript.org/ diff --git a/app/assets/stylesheets/problems.css.scss b/app/assets/stylesheets/problems.css.scss new file mode 100644 index 0000000..e08096e --- /dev/null +++ b/app/assets/stylesheets/problems.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the problems controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb new file mode 100644 index 0000000..b341960 --- /dev/null +++ b/app/controllers/problems_controller.rb @@ -0,0 +1,21 @@ +class ProblemsController < ApplicationController + before_action :set_problem, only: [:show] + + def index + @problems = Problem.paginate(page: params[:page]) + end + + def show + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_problem + @problem = Problem.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def problem_params + params.require(:problem) + end +end diff --git a/app/helpers/problems_helper.rb b/app/helpers/problems_helper.rb new file mode 100644 index 0000000..6989835 --- /dev/null +++ b/app/helpers/problems_helper.rb @@ -0,0 +1,2 @@ +module ProblemsHelper +end diff --git a/app/views/problems/_problem_pagination.erb b/app/views/problems/_problem_pagination.erb new file mode 100644 index 0000000..4df9095 --- /dev/null +++ b/app/views/problems/_problem_pagination.erb @@ -0,0 +1 @@ +<%= will_paginate @problems, renderer: BootstrapPagination::Rails %> \ No newline at end of file diff --git a/app/views/problems/index.html.erb b/app/views/problems/index.html.erb new file mode 100644 index 0000000..6aa7ecf --- /dev/null +++ b/app/views/problems/index.html.erb @@ -0,0 +1,22 @@ +

Listing Problems

+ +<%= render 'problem_pagination' %> + + + + + + + + + + <% @problems.each do |problem| %> + + + + + <% end %> + +
IDTitle
<%= problem.id %><%= link_to problem.title, problem %>
+<%= render 'problem_pagination' %> +
diff --git a/app/views/problems/show.html.erb b/app/views/problems/show.html.erb new file mode 100644 index 0000000..e165f6a --- /dev/null +++ b/app/views/problems/show.html.erb @@ -0,0 +1,16 @@ +<% if notice %> +

<%= notice %>

+<% end %> + + + +<%= panel do %> +
+ <%= sanitize @problem.content %> +
+<% end %> +
+ <%= link_to 'Dieses Problem auf projecteuler.net', @problem.translation.original_url, target: '_blank' %> +
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index c167245..65e9153 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :problems, only: [:index, :show] resources :translations # The priority is based upon order of creation: first created -> highest priority. diff --git a/db/seeds.rb b/db/seeds.rb index d58d337..ed60ace 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -6,9 +6,14 @@ # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) +Translation.delete_all +Problem.delete_all + for i in 1..103 do - Translation.create( + translation = Translation.create( + problem_id: i, title: "Problem Nummer #{i}", content: "Das hier ist der Inhalt von Problem #{i}.
Hier ist die zweite Zeile." ) -end \ No newline at end of file + Problem.create(id: i, translation: translation) +end diff --git a/test/controllers/problems_controller_test.rb b/test/controllers/problems_controller_test.rb new file mode 100644 index 0000000..57a7e39 --- /dev/null +++ b/test/controllers/problems_controller_test.rb @@ -0,0 +1,14 @@ +require 'test_helper' + +class ProblemsControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + end + + test "should get show" do + get :show, id: 1 + assert_response :success + end + +end diff --git a/test/helpers/problems_helper_test.rb b/test/helpers/problems_helper_test.rb new file mode 100644 index 0000000..1de2c21 --- /dev/null +++ b/test/helpers/problems_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class ProblemsHelperTest < ActionView::TestCase +end