1
0
mirror of https://github.com/projekteuler/projekteuler.git synced 2025-12-10 08:46:41 +01:00

Add controller for Problems with index and show actions

This commit is contained in:
Philipp Fischbeck 2014-12-29 16:16:57 +01:00
parent d1470f391e
commit 06ab2e4cab
11 changed files with 94 additions and 2 deletions

View File

@ -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/

View File

@ -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/

View File

@ -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

View File

@ -0,0 +1,2 @@
module ProblemsHelper
end

View File

@ -0,0 +1 @@
<%= will_paginate @problems, renderer: BootstrapPagination::Rails %>

View File

@ -0,0 +1,22 @@
<h1>Listing Problems</h1>
<%= render 'problem_pagination' %>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Title</th>
</tr>
</thead>
<tbody>
<% @problems.each do |problem| %>
<tr>
<td><%= problem.id %></td>
<td><%= link_to problem.title, problem %></td>
</tr>
<% end %>
</tbody>
</table>
<%= render 'problem_pagination' %>
<br>

View File

@ -0,0 +1,16 @@
<% if notice %>
<p id="notice"><%= notice %></p>
<% end %>
<div class="page-header">
<h1><%= @problem.title %> <small>Problem <%= @problem.id %></small></h1>
</div>
<%= panel do %>
<div class="panel-body problem-content">
<%= sanitize @problem.content %>
</div>
<% end %>
<div class="text-center">
<%= link_to 'Dieses Problem auf projecteuler.net', @problem.translation.original_url, target: '_blank' %>
</div>

View File

@ -1,4 +1,5 @@
Rails.application.routes.draw do Rails.application.routes.draw do
resources :problems, only: [:index, :show]
resources :translations resources :translations
# The priority is based upon order of creation: first created -> highest priority. # The priority is based upon order of creation: first created -> highest priority.

View File

@ -6,9 +6,14 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first) # Mayor.create(name: 'Emanuel', city: cities.first)
Translation.delete_all
Problem.delete_all
for i in 1..103 do for i in 1..103 do
Translation.create( translation = Translation.create(
problem_id: i,
title: "Problem Nummer #{i}", title: "Problem Nummer #{i}",
content: "Das hier ist der Inhalt von <b>Problem #{i}</b>.<br />Hier ist die zweite Zeile." content: "Das hier ist der Inhalt von <b>Problem #{i}</b>.<br />Hier ist die zweite Zeile."
) )
end Problem.create(id: i, translation: translation)
end

View File

@ -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

View File

@ -0,0 +1,4 @@
require 'test_helper'
class ProblemsHelperTest < ActionView::TestCase
end