-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ActionController::Parameters.each_value methods rails/rails#33979
- Loading branch information
Showing
20 changed files
with
475 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the EnglishScores controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
body { | ||
background-color: #fff; | ||
color: #333; | ||
margin: 33px; | ||
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; | ||
} | ||
} | ||
|
||
th { | ||
padding-bottom: 5px; | ||
} | ||
|
||
td { | ||
padding: 0 5px 7px; | ||
} | ||
|
||
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 7px 0; | ||
margin-bottom: 20px; | ||
background-color: #f0f0f0; | ||
|
||
h2 { | ||
text-align: left; | ||
font-weight: bold; | ||
padding: 5px 5px 5px 15px; | ||
font-size: 12px; | ||
margin: -7px -7px 0; | ||
background-color: #c00; | ||
color: #fff; | ||
} | ||
|
||
ul li { | ||
font-size: 12px; | ||
list-style: square; | ||
} | ||
} | ||
|
||
label { | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
class EnglishScoresController < ApplicationController | ||
before_action :set_english_score, only: [:show, :edit, :update, :destroy] | ||
|
||
# GET /english_scores | ||
# GET /english_scores.json | ||
def index | ||
@english_scores = EnglishScore.all | ||
end | ||
|
||
# GET /english_scores/1 | ||
# GET /english_scores/1.json | ||
def show | ||
end | ||
|
||
# GET /english_scores/new | ||
def new | ||
@english_score = EnglishScore.new | ||
end | ||
|
||
# GET /english_scores/1/edit | ||
def edit | ||
end | ||
|
||
# POST /english_scores | ||
# POST /english_scores.json | ||
def create | ||
@english_score = EnglishScore.new(english_score_params.merge(passed)) | ||
|
||
respond_to do |format| | ||
if @english_score.save | ||
format.html { redirect_to @english_score, notice: 'English score was successfully created.' } | ||
format.json { render :show, status: :created, location: @english_score } | ||
else | ||
format.html { render :new } | ||
format.json { render json: @english_score.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /english_scores/1 | ||
# PATCH/PUT /english_scores/1.json | ||
def update | ||
respond_to do |format| | ||
if @english_score.update(english_score_params.merge(passed)) | ||
format.html { redirect_to @english_score, notice: 'English score was successfully updated.' } | ||
format.json { render :show, status: :ok, location: @english_score } | ||
else | ||
format.html { render :edit } | ||
format.json { render json: @english_score.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /english_scores/1 | ||
# DELETE /english_scores/1.json | ||
def destroy | ||
@english_score.destroy | ||
respond_to do |format| | ||
format.html { redirect_to english_scores_url, notice: 'English score was successfully destroyed.' } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_english_score | ||
@english_score = EnglishScore.find(params[:id]) | ||
end | ||
|
||
# Never trust parameters from the scary internet, only allow the white list through. | ||
def english_score_params | ||
params.require(:english_score).permit(:name, :reading, :writing, :speaking, :listening) | ||
end | ||
|
||
def passed | ||
# The following line raises LocalJumpError (no block given) | ||
# because each_value method requires block, does not | ||
# returns Enumerator object when block is not given. | ||
# { passed: english_score_params.each_value.map(&:to_i).sum / 4.0 >= 70.0 } | ||
|
||
total = 0 | ||
english_score_params.each_value do |score| | ||
total += score.to_i | ||
end | ||
{ passed: total / 4.0 >= 70.0 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module EnglishScoresHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class EnglishScore < ApplicationRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
json.extract! english_score, :id, :name, :reading, :writing, :speaking, :listening, :passed, :created_at, :updated_at | ||
json.url english_score_url(english_score, format: :json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<%= form_with(model: english_score, local: true) do |form| %> | ||
<% if english_score.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(english_score.errors.count, "error") %> prohibited this english_score from being saved:</h2> | ||
|
||
<ul> | ||
<% english_score.errors.full_messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= form.label :name %> | ||
<%= form.text_field :name %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :reading %> | ||
<%= form.number_field :reading %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :writing %> | ||
<%= form.number_field :writing %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :speaking %> | ||
<%= form.number_field :speaking %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :listening %> | ||
<%= form.number_field :listening %> | ||
</div> | ||
|
||
<div class="actions"> | ||
<%= form.submit %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing English Score</h1> | ||
|
||
<%= render 'form', english_score: @english_score %> | ||
<%= link_to 'Show', @english_score %> | | ||
<%= link_to 'Back', english_scores_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<h1>English Scores</h1> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Reading</th> | ||
<th>Writing</th> | ||
<th>Speaking</th> | ||
<th>Listening</th> | ||
<th>Passed</th> | ||
<th colspan="3"></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @english_scores.each do |english_score| %> | ||
<tr> | ||
<td><%= english_score.name %></td> | ||
<td><%= english_score.reading %></td> | ||
<td><%= english_score.writing %></td> | ||
<td><%= english_score.speaking %></td> | ||
<td><%= english_score.listening %></td> | ||
<td><%= english_score.passed %></td> | ||
<td><%= link_to 'Show', english_score %></td> | ||
<td><%= link_to 'Edit', edit_english_score_path(english_score) %></td> | ||
<td><%= link_to 'Destroy', english_score, method: :delete, data: { confirm: 'Are you sure?' } %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
<br> | ||
|
||
<%= link_to 'New English Score', new_english_score_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.array! @english_scores, partial: 'english_scores/english_score', as: :english_score |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>New English Score</h1> | ||
|
||
<%= render 'form', english_score: @english_score %> | ||
<%= link_to 'Back', english_scores_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<p> | ||
<strong>Name:</strong> | ||
<%= @english_score.name %> | ||
</p> | ||
|
||
<p> | ||
<strong>Reading:</strong> | ||
<%= @english_score.reading %> | ||
</p> | ||
|
||
<p> | ||
<strong>Writing:</strong> | ||
<%= @english_score.writing %> | ||
</p> | ||
|
||
<p> | ||
<strong>Speaking:</strong> | ||
<%= @english_score.speaking %> | ||
</p> | ||
|
||
<p> | ||
<strong>Listening:</strong> | ||
<%= @english_score.listening %> | ||
</p> | ||
|
||
<p> | ||
<strong>Passed:</strong> | ||
<%= @english_score.passed %> | ||
</p> | ||
|
||
<%= link_to 'Edit', edit_english_score_path(@english_score) %> | | ||
<%= link_to 'Back', english_scores_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial! "english_scores/english_score", english_score: @english_score |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
Rails.application.routes.draw do | ||
resources :english_scores | ||
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateEnglishScores < ActiveRecord::Migration[6.0] | ||
def change | ||
create_table :english_scores do |t| | ||
t.string :name | ||
t.integer :reading | ||
t.integer :writing | ||
t.integer :speaking | ||
t.integer :listening | ||
t.boolean :passed | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# This file is the source Rails uses to define your schema when running `rails | ||
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to | ||
# be faster and is potentially less error prone than running all of your | ||
# migrations from scratch. Old migrations may fail to apply correctly if those | ||
# migrations use external dependencies or application code. | ||
# | ||
# It's strongly recommended that you check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(version: 2019_06_09_061029) do | ||
|
||
# These are extensions that must be enabled in order to support this database | ||
enable_extension "plpgsql" | ||
|
||
create_table "english_scores", force: :cascade do |t| | ||
t.string "name" | ||
t.integer "reading" | ||
t.integer "writing" | ||
t.integer "speaking" | ||
t.integer "listening" | ||
t.boolean "passed" | ||
t.datetime "created_at", precision: 6, null: false | ||
t.datetime "updated_at", precision: 6, null: false | ||
end | ||
|
||
end |
Oops, something went wrong.