1
0
mirror of https://github.com/projekteuler/projekteuler.git synced 2026-01-27 02:28:50 +01:00

Add problem type

This commit is contained in:
2014-11-30 16:42:50 +01:00
parent bbbadc5184
commit b7a0303206
20 changed files with 339 additions and 0 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,69 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}
a {
color: #000;
&:visited {
color: #666;
}
&:hover {
color: #fff;
background-color: #000;
}
}
div {
&.field, &.actions {
margin-bottom: 10px;
}
}
#notice {
color: green;
}
.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}
#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff;
}
ul li {
font-size: 12px;
list-style: square;
}
}

View File

@@ -0,0 +1,74 @@
class ProblemsController < ApplicationController
before_action :set_problem, only: [:show, :edit, :update, :destroy]
# GET /problems
# GET /problems.json
def index
@problems = Problem.all
end
# GET /problems/1
# GET /problems/1.json
def show
end
# GET /problems/new
def new
@problem = Problem.new
end
# GET /problems/1/edit
def edit
end
# POST /problems
# POST /problems.json
def create
@problem = Problem.new(problem_params)
respond_to do |format|
if @problem.save
format.html { redirect_to @problem, notice: 'Problem was successfully created.' }
format.json { render :show, status: :created, location: @problem }
else
format.html { render :new }
format.json { render json: @problem.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /problems/1
# PATCH/PUT /problems/1.json
def update
respond_to do |format|
if @problem.update(problem_params)
format.html { redirect_to @problem, notice: 'Problem was successfully updated.' }
format.json { render :show, status: :ok, location: @problem }
else
format.html { render :edit }
format.json { render json: @problem.errors, status: :unprocessable_entity }
end
end
end
# DELETE /problems/1
# DELETE /problems/1.json
def destroy
@problem.destroy
respond_to do |format|
format.html { redirect_to problems_url, notice: 'Problem was successfully destroyed.' }
format.json { head :no_content }
end
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).permit(:title, :content)
end
end

View File

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

2
app/models/problem.rb Normal file
View File

@@ -0,0 +1,2 @@
class Problem < ActiveRecord::Base
end

View File

@@ -0,0 +1,25 @@
<%= form_for(@problem) do |f| %>
<% if @problem.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@problem.errors.count, "error") %> prohibited this problem from being saved:</h2>
<ul>
<% @problem.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :content %><br>
<%= f.text_area :content %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@@ -0,0 +1,6 @@
<h1>Editing problem</h1>
<%= render 'form' %>
<%= link_to 'Show', @problem %> |
<%= link_to 'Back', problems_path %>

View File

@@ -0,0 +1,27 @@
<h1>Listing problems</h1>
<table>
<thead>
<tr>
<th>Title</th>
<th>Content</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @problems.each do |problem| %>
<tr>
<td><%= problem.title %></td>
<td><%= problem.content %></td>
<td><%= link_to 'Show', problem %></td>
<td><%= link_to 'Edit', edit_problem_path(problem) %></td>
<td><%= link_to 'Destroy', problem, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Problem', new_problem_path %>

View File

@@ -0,0 +1,4 @@
json.array!(@problems) do |problem|
json.extract! problem, :id, :title, :content
json.url problem_url(problem, format: :json)
end

View File

@@ -0,0 +1,5 @@
<h1>New problem</h1>
<%= render 'form' %>
<%= link_to 'Back', problems_path %>

View File

@@ -0,0 +1,14 @@
<p id="notice"><%= notice %></p>
<p>
<strong>Title:</strong>
<%= @problem.title %>
</p>
<p>
<strong>Content:</strong>
<%= @problem.content %>
</p>
<%= link_to 'Edit', edit_problem_path(@problem) %> |
<%= link_to 'Back', problems_path %>

View File

@@ -0,0 +1 @@
json.extract! @problem, :id, :title, :content, :created_at, :updated_at