diff --git a/README.md b/README.md index 7db80e4..9f5ba3f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # README +* [CPM-programリンク](https://www.koeki-prj.org/CPM-program) + This README would normally document whatever steps are necessary to get the application up and running. diff --git a/all-memo.txt b/all-memo.txt new file mode 100644 index 0000000..28f9558 --- /dev/null +++ b/all-memo.txt @@ -0,0 +1,44 @@ +1/21までに作るもの +演習機能 +・ジュニアドクター講義が終わったら回答するクイズを選んでもらうページ +・回答してもらうページ +・(回答の答えが書いてあるページ) +クイズ形式学習機能 +・クイズを回答するページ + +ここの段階では、クイズの得点や演習機能の得点は取らない(取れない) + + +* ヘッダーから消したやつ + #
  • <%= link_to("ユーザー一覧", "/users/index") %>
  • + #
  • <%= link_to("スライド一覧","/posts/index")%>
  • + +* posts_controller.rbの投稿を消すアクション + def destroy + @post = Post.find_by(id: params[:id]) + @post.destroy + flash[:notice] = "スライドを削除しました" + redirect_to("/posts/index") + end + + * show.html.erbから消した削除ボタンの部分 + <%= link_to("削除", "/posts/#{@post.id}/destroy", {method: "post"}) %> + + *自分のパソコンだけじゃなく、他の人のパソコンでも繋がるようにするには + rails s -b 0.0.0.0 + +ーーーrails説明ーーー +railsではcssが全てのerbファイルに同時についてしまうため、クラス名を慎重に考えながら書くことが大切。 +別々にできる方法もあるけど現環境壊すの怖すぎるのでやらない,,,,, + + +viの中身を変更,かえた + +ヘッダーのサインアップの部分 + +
  • <%= link_to("新規登録", "/CPM-program/signup")%>
  • + + +
  • <%= link_to(image_tag("/mail-icon.png"), "/CPM-program/users/index") %>
  • +
  • <%= link_to(image_tag("/ring-icon.png"), "/CPM-program/users/index") %>
  • +
  • <%= link_to(image_tag("/human-icon.png"), "/CPM-program/users/index") %>
  • \ No newline at end of file diff --git a/app/assets/stylesheets/posts.css b/app/assets/stylesheets/posts.css index 97eff0a..8d9dbc1 100644 --- a/app/assets/stylesheets/posts.css +++ b/app/assets/stylesheets/posts.css @@ -15,7 +15,6 @@ overflow: hidden; box-shadow: 0 0 8px gray; width: 400px; - text-align: center; margin-left: 60px; margin-top: 60px; font-weight: bold; diff --git a/app/assets/stylesheets/quiz.css b/app/assets/stylesheets/quiz.css new file mode 100644 index 0000000..a6388f9 --- /dev/null +++ b/app/assets/stylesheets/quiz.css @@ -0,0 +1,74 @@ +/*---------------------------------------------------クイズの中----------------------------------*/ +.quiz-inner{ + margin-left: 100px; + margin-right: 100px; + margin-top: 50px; + margin-bottom: 50px; + height: 100vh; +} +caption{ + margin-bottom: 5px; +} +table{ + padding: 5px; +} +th{ + padding: 10px; +} +td{ + padding: 10px; +} +.page-title{ + border-bottom: double 5px #17adec; +} +.quiz-title{ + margin-top: 50px; +} +.quiz-text{ + margin-left: 100px; + font-size: 1.2rem; +} +.quiz-text a{ + font-weight: bold; +} +.select{ + color: brown; +} +.question{ + color: #fff; +} +.blackboard-box{ + background: #104300; + margin: 4em 0; + padding: 1em 1em 0 1em; + border: 8px solid #a60; + box-shadow: 2px 2px 4px #999, 2px 2px 2px #020 inset; + + } + + .blackboard-box p{ + margin: 0; + padding: 0; + color: #fff; + text-shadow: 0px 0px 2px #fff; + } + + .chalk1{ + display: block; + margin-top: 10px; + margin-left: 90%; + border: solid 3px #fff; + width: 15px; + height: 6px; + border-radius: 3px 2px 0 2px; + } + + .chalk2{ + display: block; + margin-top: -6px; + margin-left: calc(90% - 30px); + border: solid 3px #ffee58; + width: 20px; + height: 6px; + border-radius: 3px 2px 0 2px; + } \ No newline at end of file diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 0c11e98..a97f29b 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,4 +1,6 @@ class PostsController < ApplicationController + + def index @posts = Post.all.order(created_at: :desc) end @@ -11,13 +13,14 @@ @post = Post.new end + protect_from_forgery except: :create def create @post = Post.new(content: params[:content]) if @post.save - flash[:notice] = "スライドを作成しました" - redirect_to("/posts/index") + flash[:notice] = "応用問題を送信しました" + redirect_to("/CPM-program/posts/index") else - render("posts/new") + render("/CPM-program/posts/new") end end @@ -25,22 +28,16 @@ @post = Post.find_by(id: params[:id]) end + protect_from_forgery except: :update def update @post = Post.find_by(id: params[:id]) @post.content = params[:content] if @post.save - flash[:notice] = "スライドを編集しました" - redirect_to("/posts/index") + flash[:notice] = "応用問題を修正しました" + redirect_to("/CPM-program/posts/index") else - render("posts/edit") + render("/CPM-program/posts/edit") end end - - def destroy - @post = Post.find_by(id: params[:id]) - @post.destroy - flash[:notice] = "スライドを削除しました" - redirect_to("/posts/index") - end - + end \ No newline at end of file diff --git a/app/controllers/quiz_controller.rb b/app/controllers/quiz_controller.rb new file mode 100644 index 0000000..ccb26fc --- /dev/null +++ b/app/controllers/quiz_controller.rb @@ -0,0 +1,13 @@ +class QuizController < ApplicationController + def index + end + + def new + end + + def show + end + + def edit + end +end diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb new file mode 100644 index 0000000..4305b16 --- /dev/null +++ b/app/controllers/rooms_controller.rb @@ -0,0 +1,4 @@ +class RoomsController < ApplicationController + def show + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b3668ca..ae3d896 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -12,13 +12,14 @@ end + protect_from_forgery except: :create def create @user = User.new(name: params[:name], email: params[:email]) if @user.save flash[:notice] ="ユーザー登録が完了しました" - redirect_to("/users/#{@user.id}") + redirect_to("/CPM-program/users/#{@user.id}") else - render("users/new") + render("/CPM-program/users/new") end end diff --git a/app/helpers/quiz_helper.rb b/app/helpers/quiz_helper.rb new file mode 100644 index 0000000..918525e --- /dev/null +++ b/app/helpers/quiz_helper.rb @@ -0,0 +1,2 @@ +module QuizHelper +end diff --git a/app/helpers/rooms_helper.rb b/app/helpers/rooms_helper.rb new file mode 100644 index 0000000..1d0f4c7 --- /dev/null +++ b/app/helpers/rooms_helper.rb @@ -0,0 +1,2 @@ +module RoomsHelper +end diff --git a/app/javascript/quiz.js b/app/javascript/quiz.js new file mode 100644 index 0000000..e2d6039 --- /dev/null +++ b/app/javascript/quiz.js @@ -0,0 +1,94 @@ +//初期設定 +q_sel = 3; //選択肢の数 +q_max = 3; //出題数 + + + +setReady(); + +//初期設定 +function setReady() { +count = 0; //問題番号 +ansers = new Array(); //解答記録 +seikai = 0; // ++++++ + +//問題と解答 +qa = new Array(); +qa[0] = ["print()の処理方法は?","()内の文字列を出力できる","()内の文字列を出力して、最後に改行が追加される","キーボードで打ち込んだ文字を取り出す",1]; +qa[1] = ["getsの処理方法は?","キーボードで打ち込んだ文字を取り出す","コメント文にする","対応する値を整数の文字列に置き換える",1]; +qa[2] = ["%d、%f、%sが使える出力形式は?","print","gets","printf",3]; +qa[3] = ["対応する値を文字列に置き換えるのはどれ?","%d","%s","%f",2]; +qa[4] = ["「#」を使った時はどのように処理が行われる?","改行される","掛け算される","コメントアウトされる",3]; +qa[5] = ["プログラムの一部を実行させなかったり、同じ処理を何回も繰り返したりすることができるものは?","制御構造","破壊的操作","乱数",1]; +qa[6] = ["redoの処理内容は?","処理を中止して、ループを終わらせる","条件を判断せず、処理を最初からやり直す","処理をスキップして、次のループに移る",2]; +qa[7] = ["forの処理方法は?","配列や範囲などの複数の間を順に変数に代入する","配列の要素を小さい順に並べ替えた結果を返す","配列の末尾に要素を追加する",1]; +qa[8] = ["変数とは何か?","値につける名前","複数の値をひとまとめにできるもの","数字の中からランダムに発生させる数",1]; +qa[4] = ["Time.now を使うと何ができる?","一時停止できる","配列の要素を小さい順に並べ替えれる","現在の時刻を受け取ることができる",3]; + +//最初の問題 +quiz(); +} + +//問題表示 +function quiz() { +var s, n; +//問題 +md = Math.floor(Math.random() * qa.length); //乱数 +document.getElementById("text_q").innerHTML = (count + 1) + "問目:" + qa[md][0]; +//選択肢 +s = ""; +for (n=1;n<=q_sel;n++) { +if (qa[md][n] != "") { +s += "【" + n + ":" + qa[md][n] + "】"; +} +} +document.getElementById("text_s").innerHTML = s; +// qa.splice(md,1); // ------------------ +} + +//解答表示 +function anser(num) { +var s; +s = (count + 1) + "問目:"; +//答え合わせ +if (num == qa[md][q_sel + 1]) { +//正解 +ansers[count] = "○"; +seikai ++; // ++++++ +} else { +ansers[count] = "×"; +} +s += ansers[count] + qa[md][num]; +document.getElementById("text_a").innerHTML = s; + +qa.splice(md,1); console.log(qa); // ++++++++++ +//次の問題を表示 +count++; +if (count < q_max) { +quiz(); +} else { +//終了 +s = ""; +//1行目 +s += ""; +for (n=0;n"; +} +s += ""; +//2行目 +s += ""; +for (n=0;n"; +} +s += ""; +s += "
    成績発表
    問題
    成績
    "; +s += "
    成績は、" + seikai + "点です"; // +++++++ + +document.getElementById("text_q").innerHTML = s; +//次の選択肢 +s = "【前のページに戻る】"; +s += "【同じ問題を最初から】"; +s += "【次の問題に進む】"; +document.getElementById("text_s").innerHTML = s; +} +} \ No newline at end of file diff --git a/app/models/post.rb b/app/models/post.rb index 19e2d47..2c52b32 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1,3 +1,3 @@ class Post < ApplicationRecord - validates :content, {presence: true, length:{maximum: 160}} + validates :content, {presence: true} end diff --git a/app/views/home/top.html.erb b/app/views/home/top.html.erb index 14feb1e..187e460 100644 --- a/app/views/home/top.html.erb +++ b/app/views/home/top.html.erb @@ -17,21 +17,21 @@
    -
    +
    -

    Rubyスライド

    +

    Ruby問題

    • 1.プログラミングとは

      ・パソコンの使い方
      ・キーボードの打ち方
      ・プログラムの書き方

    • 2.Rubyに触れてみよう

      ・値とは
      ・Rubyの計算
      ・変数とは

    • @@ -59,7 +59,7 @@
    -

    今までのイベントスライド

    +

    今までの応用問題

    • 8月

      JavaScriptとは

    • 9月

      Rubyを強化しよう!

    • diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d203c7a..a4622bd 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,7 +1,7 @@ - TweetApp + CPM-program <%= csrf_meta_tags %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> @@ -11,22 +11,19 @@ diff --git a/app/views/posts/edit.html.erb b/app/views/posts/edit.html.erb index 6616425..21bdd72 100644 --- a/app/views/posts/edit.html.erb +++ b/app/views/posts/edit.html.erb @@ -1,7 +1,7 @@

      編集する

      - <%= form_tag("/posts/#{@post.id}/update") do %> + <%= form_tag("/CPM-program/posts/#{@post.id}/update") do %>
      <% @post.errors.full_messages.each do |message| %> diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 2806926..d15e074 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -1,9 +1,9 @@
      -

      スライド一覧

      +

      みんなの回答一覧

      <% @posts.each do |post| %>
      - <%= link_to(post.content, "/posts/#{post.id}")%> + <%= link_to(post.content, "/CPM-program/posts/#{post.id}")%>
      <% end %>
      diff --git a/app/views/posts/new.html.erb b/app/views/posts/new.html.erb index f11ff6c..72d837b 100644 --- a/app/views/posts/new.html.erb +++ b/app/views/posts/new.html.erb @@ -1,7 +1,10 @@
      -

      スライドを作成する

      - <%= form_tag("/posts/create") do %> +

      問題:配列likeの中に自分の好きなものを値として3つ入れて、printfで配列の中身を表示させてください。

      +

      応用問題に回答する

      +

      例: 伊藤理乃

      +

         puts "こんにちは!"

      + <%= form_tag("/CPM-program/posts/create") do %>
      <% @post.errors.full_messages.each do |message| %> @@ -11,7 +14,7 @@ <% end %> - +
      <% end %> diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index 209b773..3a2a28e 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -8,8 +8,7 @@ <%= @post.created_at %>
      - <%= link_to("編集", "/posts/#{@post.id}/edit") %> - <%= link_to("削除", "/posts/#{@post.id}/destroy", {method: "post"}) %> + <%= link_to("編集", "/CPM-program/posts/#{@post.id}/edit") %>
      diff --git a/app/views/quiz/edit.html.erb b/app/views/quiz/edit.html.erb new file mode 100644 index 0000000..c7e9fde --- /dev/null +++ b/app/views/quiz/edit.html.erb @@ -0,0 +1,2 @@ +

      Quiz#edit

      +

      Find me in app/views/quiz/edit.html.erb

      diff --git a/app/views/quiz/index.html.erb b/app/views/quiz/index.html.erb new file mode 100644 index 0000000..d998827 --- /dev/null +++ b/app/views/quiz/index.html.erb @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + CPM-program + + + +
      +

      Rubyクイズ①

      +
      +
      +
      +
      +
      +
      +

      選択

      +
      +
      +
      +

      解答

      +
      +
      +
      +
      + © 2022 プチ論研究-伊藤理乃 +
      + + diff --git a/app/views/quiz/new.html.erb b/app/views/quiz/new.html.erb new file mode 100644 index 0000000..4b68784 --- /dev/null +++ b/app/views/quiz/new.html.erb @@ -0,0 +1,2 @@ +

      Quiz#new

      +

      Find me in app/views/quiz/new.html.erb

      diff --git a/app/views/quiz/quiz-2.html b/app/views/quiz/quiz-2.html new file mode 100644 index 0000000..a6a993d --- /dev/null +++ b/app/views/quiz/quiz-2.html @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + CPM-program + + + +
      +

      Rubyクイズ①

      +
      +
      +
      +
      +
      +
      +

      1~3のどれかをクリックしてね

      +
      +
      +
      +

      あなたの答えは

      +
      +
      +
      +
      + © 2022 プチ論研究-伊藤理乃 +
      + + + diff --git a/app/views/quiz/quiz.js b/app/views/quiz/quiz.js new file mode 100644 index 0000000..32b6f18 --- /dev/null +++ b/app/views/quiz/quiz.js @@ -0,0 +1,93 @@ +//初期設定 +q_sel = 3; //選択肢の数 +q_max = 3; //出題数 + + + +setReady(); + +//初期設定 +function setReady() { +count = 0; //問題番号 +ansers = new Array(); //解答記録 +seikai = 0; // ++++++ + +//問題と解答 +qa = new Array(); +qa[0] = ["print()の処理方法は?","()内の文字列を出力できる","()内の文字列を出力して、最後に改行が追加される","キーボードで打ち込んだ文字を取り出す",1]; +qa[1] = ["getsの処理方法は?","キーボードで打ち込んだ文字を取り出す","コメント文にする","対応する値を整数の文字列に置き換える",1]; +qa[2] = ["%d、%f、%sが使える出力形式は?","print","gets","printf",3]; +qa[3] = ["対応する値を文字列に置き換えるのはどれ?","%d","%s","%f",2]; +qa[4] = ["「#」を使った時はどのように処理が行われる?","改行される","掛け算される","コメントアウトされる",3]; +qa[5] = ["プログラムの一部を実行させなかったり、同じ処理を何回も繰り返したりすることができるものは?","制御構造","破壊的操作","乱数",1]; +qa[6] = ["redoの処理内容は?","処理を中止して、ループを終わらせる","条件を判断せず、処理を最初からやり直す","処理をスキップして、次のループに移る",2]; +qa[7] = ["forの処理方法は?","配列や範囲などの複数の間を順に変数に代入する","配列の要素を小さい順に並べ替えた結果を返す","配列の末尾に要素を追加する",1]; +qa[8] = ["変数とは何か?","値につける名前","複数の値をひとまとめにできるもの","数字の中からランダムに発生させる数",1]; + +//最初の問題 +quiz(); +} + +//問題表示 +function quiz() { +var s, n; +//問題 +md = Math.floor(Math.random() * qa.length); //乱数 +document.getElementById("text_q").innerHTML = (count + 1) + "問目:" + qa[md][0]; +//選択肢 +s = ""; +for (n=1;n<=q_sel;n++) { +if (qa[md][n] != "") { +s += "【" + n + ":" + qa[md][n] + "】"; +} +} +document.getElementById("text_s").innerHTML = s; +// qa.splice(md,1); // ------------------ +} + +//解答表示 +function anser(num) { +var s; +s = (count + 1) + "問目:"; +//答え合わせ +if (num == qa[md][q_sel + 1]) { +//正解 +ansers[count] = "○"; +seikai ++; // ++++++ +} else { +ansers[count] = "×"; +} +s += ansers[count] + qa[md][num]; +document.getElementById("text_a").innerHTML = s; + +qa.splice(md,1); console.log(qa); // ++++++++++ +//次の問題を表示 +count++; +if (count < q_max) { +quiz(); +} else { +//終了 +s = ""; +//1行目 +s += ""; +for (n=0;n"; +} +s += ""; +//2行目 +s += ""; +for (n=0;n"; +} +s += ""; +s += "
      成績発表
      問題
      成績
      "; +s += "
      成績は、" + seikai + "点です"; // +++++++ + +document.getElementById("text_q").innerHTML = s; +//次の選択肢 +s = "【前のページに戻る】"; +s += "【同じ問題を最初から】"; +s += "【次の問題に進む】"; +document.getElementById("text_s").innerHTML = s; +} +} \ No newline at end of file diff --git a/app/views/quiz/show.html.erb b/app/views/quiz/show.html.erb new file mode 100644 index 0000000..e78bc20 --- /dev/null +++ b/app/views/quiz/show.html.erb @@ -0,0 +1,2 @@ +

      Quiz#show

      +

      Find me in app/views/quiz/show.html.erb

      diff --git a/app/views/rooms/show.html.erb b/app/views/rooms/show.html.erb new file mode 100644 index 0000000..6efa366 --- /dev/null +++ b/app/views/rooms/show.html.erb @@ -0,0 +1,2 @@ +

      Rooms#show

      +

      Find me in app/views/rooms/show.html.erb

      diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index a625b11..e9a2da6 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,14 +1,11 @@
      - <% @users.each do |user| %>
      - - <%= link_to(user.name, "/users/#{user.id}") %> + <%= link_to(user.name, "/CPM-program/users/#{user.id}") %>
      - <% end%>
      diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index db9f1bf..c66ec80 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -9,7 +9,7 @@
      <% end %> - <%= form_tag("/users/create") do %> + <%= form_tag("/CPM-program/users/create") do %>

      ユーザー名

      メールアドレス

      diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 119ff05..7290fb8 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -5,7 +5,7 @@

      <%= @user.name %>

      <%= @user.email %>

      - <%= link_to("編集", "/users/#{@user.id}/edit")%> + <%= link_to("編集", "/CPM-program/users/#{@user.id}/edit")%>
      \ No newline at end of file diff --git a/config.ru b/config.ru index 4a3c09a..8cb7389 100644 --- a/config.ru +++ b/config.ru @@ -2,5 +2,7 @@ require_relative "config/environment" +map ActionController::Base.config.relative_url_root || "/" do run Rails.application +end Rails.application.load_server diff --git a/config/environments/development.rb b/config/environments/development.rb index 8500f45..992c172 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -59,6 +59,9 @@ # Suppress logger output for asset requests. config.assets.quiet = true + config.hosts.clear + Rails.application.config.relative_url_root = "/CPM-program" + # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true diff --git a/config/puma.rb b/config/puma.rb index daaf036..4026dc1 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -15,7 +15,7 @@ # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch("PORT") { 1200 } # Specifies the `environment` that Puma will run in. # diff --git a/config/routes.rb b/config/routes.rb index 23b3c79..4ad9504 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,8 @@ Rails.application.routes.draw do + get 'quiz/index' + get 'quiz/new' + get 'quiz/show' + get 'quiz/edit' get "users/:id/edit" => "users#edit" post "users/create" => "users#create" get "signup" => "users#new" @@ -15,4 +19,7 @@ get "/" => "home#top" get "about" => "home#about" + + get "quiz/index" => "quiz#index" + get "seikou" => "quiz#quiz-2" end diff --git a/test/controllers/quiz_controller_test.rb b/test/controllers/quiz_controller_test.rb new file mode 100644 index 0000000..2961998 --- /dev/null +++ b/test/controllers/quiz_controller_test.rb @@ -0,0 +1,23 @@ +require "test_helper" + +class QuizControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get quiz_index_url + assert_response :success + end + + test "should get new" do + get quiz_new_url + assert_response :success + end + + test "should get show" do + get quiz_show_url + assert_response :success + end + + test "should get edit" do + get quiz_edit_url + assert_response :success + end +end diff --git a/test/controllers/rooms_controller_test.rb b/test/controllers/rooms_controller_test.rb new file mode 100644 index 0000000..8c5efb6 --- /dev/null +++ b/test/controllers/rooms_controller_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class RoomsControllerTest < ActionDispatch::IntegrationTest + test "should get show" do + get rooms_show_url + assert_response :success + end +end