質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

Q&A

解決済

1回答

759閲覧

コメントを送信しページを移動したい

yozakura10

総合スコア8

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

0グッド

0クリップ

投稿2020/10/26 02:57

前提・実現したいこと
prototypeにコメント蘭を作成しました
そのコメントを送信して無事にページを移動したいです

発生している問題・エラーメッセージ
ruby on railsでの作成途中でおきました
エラーメッセージ

エラー文です

ruby

1 2Routing Error 3uninitialized constant CommentsController Did you mean? ActionController 4Rails.root: /Users/kamiyaryota/Desktop/projects/protospace-31035 5 6Application Trace | Framework Trace | Full Trace 7Routes 8Routes match in priority from top to bottom 9 10Helper HTTP Verb Path Controller#Action 11Path / Url 12Path Match 13new_user_session_path GET /users/sign_in(.:format) 14devise/sessions#new 15 16user_session_path POST /users/sign_in(.:format) 17devise/sessions#create 18 19destroy_user_session_path DELETE /users/sign_out(.:format) 20devise/sessions#destroy 21 22new_user_password_path GET /users/password/new(.:format) 23devise/passwords#new 24 25edit_user_password_path GET /users/password/edit(.:format) 26devise/passwords#edit 27 28user_password_path PATCH /users/password(.:format) 29devise/passwords#update 30 31PUT /users/password(.:format) 32devise/passwords#update 33 34POST /users/password(.:format) 35devise/passwords#create 36 37cancel_user_registration_path GET /users/cancel(.:format) 38devise/registrations#cancel 39 40new_user_registration_path GET /users/sign_up(.:format) 41devise/registrations#new 42 43edit_user_registration_path GET /users/edit(.:format) 44devise/registrations#edit 45 46user_registration_path PATCH /users(.:format) 47devise/registrations#update 48 49PUT /users(.:format) 50devise/registrations#update 51 52DELETE /users(.:format) 53devise/registrations#destroy 54 55POST /users(.:format) 56devise/registrations#create 57 58root_path GET / 59prototypes#index 60 61new_user_path GET /users/new(.:format) 62users#new 63 64edit_user_path GET /users/:id/edit(.:format) 65users#edit 66 67user_path PATCH /users/:id(.:format) 68users#update 69 70PUT /users/:id(.:format) 71users#update 72 73prototype_comments_path POST /prototypes/:prototype_id/comments(.:format) 74comments#create 75 76prototypes_path POST /prototypes(.:format) 77prototypes#create 78 79new_prototype_path GET /prototypes/new(.:format) 80prototypes#new 81 82edit_prototype_path GET /prototypes/:id/edit(.:format) 83prototypes#edit 84 85prototype_path GET /prototypes/:id(.:format) 86prototypes#show 87 88PATCH /prototypes/:id(.:format) 89prototypes#update 90 91PUT /prototypes/:id(.:format) 92prototypes#update 93 94DELETE /prototypes/:id(.:format) 95prototypes#destroy 96 97users_sign_out_path GET /users/sign_out(.:format) 98devise/sessions#destroy 99 100rails_postmark_inbound_emails_path POST /rails/action_mailbox/postmark/inbound_emails(.:format) 101action_mailbox/ingresses/postmark/inbound_emails#create 102 103rails_relay_inbound_emails_path POST /rails/action_mailbox/relay/inbound_emails(.:format) 104action_mailbox/ingresses/relay/inbound_emails#create 105 106rails_sendgrid_inbound_emails_path POST /rails/action_mailbox/sendgrid/inbound_emails(.:format) 107action_mailbox/ingresses/sendgrid/inbound_emails#create 108 109rails_mandrill_inbound_health_check_path GET /rails/action_mailbox/mandrill/inbound_emails(.:format) 110action_mailbox/ingresses/mandrill/inbound_emails#health_check 111 112rails_mandrill_inbound_emails_path POST /rails/action_mailbox/mandrill/inbound_emails(.:format) 113action_mailbox/ingresses/mandrill/inbound_emails#create 114 115rails_mailgun_inbound_emails_path POST /rails/action_mailbox/mailgun/inbound_emails/mime(.:format) 116action_mailbox/ingresses/mailgun/inbound_emails#create 117 118rails_conductor_inbound_emails_path GET /rails/conductor/action_mailbox/inbound_emails(.:format) 119rails/conductor/action_mailbox/inbound_emails#index 120 121POST /rails/conductor/action_mailbox/inbound_emails(.:format) 122rails/conductor/action_mailbox/inbound_emails#create 123 124new_rails_conductor_inbound_email_path GET /rails/conductor/action_mailbox/inbound_emails/new(.:format) 125rails/conductor/action_mailbox/inbound_emails#new 126 127edit_rails_conductor_inbound_email_path GET /rails/conductor/action_mailbox/inbound_emails/:id/edit(.:format) 128rails/conductor/action_mailbox/inbound_emails#edit 129 130rails_conductor_inbound_email_path GET /rails/conductor/action_mailbox/inbound_emails/:id(.:format) 131rails/conductor/action_mailbox/inbound_emails#show 132 133PATCH /rails/conductor/action_mailbox/inbound_emails/:id(.:format) 134rails/conductor/action_mailbox/inbound_emails#update 135 136PUT /rails/conductor/action_mailbox/inbound_emails/:id(.:format) 137rails/conductor/action_mailbox/inbound_emails#update 138 139DELETE /rails/conductor/action_mailbox/inbound_emails/:id(.:format) 140rails/conductor/action_mailbox/inbound_emails#destroy 141 142rails_conductor_inbound_email_reroute_path POST /rails/conductor/action_mailbox/:inbound_email_id/reroute(.:format) 143rails/conductor/action_mailbox/reroutes#create 144 145rails_service_blob_path GET /rails/active_storage/blobs/:signed_id/*filename(.:format) 146active_storage/blobs#show 147 148rails_blob_representation_path GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) 149active_storage/representations#show 150 151rails_disk_service_path GET /rails/active_storage/disk/:encoded_key/*filename(.:format) 152active_storage/disk#show 153 154update_rails_disk_service_path PUT /rails/active_storage/disk/:encoded_token(.:format) 155active_storage/disk#update 156 157rails_direct_uploads_path POST /rails/active_storage/direct_uploads(.:format) 158active_storage/direct_uploads#create 159 160Request 161Parameters: 162 163{"authenticity_token"=>"LRKx0uCo8jiRVYt0AsO0pMVVu4t21h6/hscgNz8ZxDBnBhfbIjsQZYC74JV1bjKQwZ4Fa3/vqJQMY/Nn+4MTyg==", "comment"=>{"text"=>"aaa"}, "commit"=>"送信する", "prototype_id"=>"1"} 164Toggle session dump 165Toggle env dump 166Response 167Headers: 168 169None

routes.rbです

ruby

1Rails.application.routes.draw do 2 devise_for :users 3 root to: "prototypes#index" 4 resources :users, only: [:new, :edit, :update,] 5 resources :prototypes, only: [:new, :create, :show, :edit, :update, :destroy,] do 6 resources :comments, only: :create 7 end 8 9 devise_ 10scope :user do 11 get '/users/sign_out' => 'devise/sessions#destroy' 12 end 13 14end 15

コントローラーrbです

ruby

1class CommentsController < ApplicationController 2 def create 3 @comment = Comment.new(comment_params) 4 if @comment.save 5 redirect_to prototype_path 6 else 7 render :show 8 end 9 10 end 11 12 private 13 def comment_params 14 params.require(:comment).permit(:text).merge(user_id: current_user.id, prototype_id: params[:prototype_id]) 15 end 16end 17

edit.htmlです

ruby

1<div class="main"> 2 <div class="inner"> 3 <div class="form__wrapper"> 4 <h2 class="page-heading">プロトタイプ編集</h2> 5 <%# 部分テンプレートでフォームを表示する %> 6 <%= render partial: "form" %> 7 </div> 8 </div> 9</div>

部分テンプレートです

html

1<%= form_with model: @prototype, local: true do |f|%> 2 <div class="field"> 3 <%= f.label :title, "プロトタイプの名称" %><br /> 4 <%= f.text_field :title %> 5 </div> 6 7 <div class="field"> 8 <%= f.label :catct_copy, "キャッチコピー" %><br /> 9 <%= f.text_area :catct_copy, class: :form__text %> 10 </div> 11 12 <div class="field"> 13 <%= f.label :concept, "コンセプト" %><br /> 14 <%= f.text_area :concept, class: :form__text %> 15 </div> 16 17 <div class="field"> 18 <%= f.label :image, "プロトタイプの画像" %><br /> 19 <%= f.file_field :image %> 20 </div> 21 22 <div class="actions"> 23 <%= f.submit "保存する", class: :form__btn %> 24 </div> 25<% end %>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

redirect_to "/prototype/#{@comment.prototype.id}"に直しました

投稿2020/10/26 03:23

yozakura10

総合スコア8

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問