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

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

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

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

Ruby on Rails

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

Q&A

1回答

1265閲覧

NoMethodError を解決したい

adonson

総合スコア12

Ruby

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

Ruby on Rails

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

0グッド

0クリップ

投稿2020/04/28 03:07

編集2022/01/12 10:55

イメージ説明現在PCの構成部品を選択し、そのPCの名前と構成部品をPCテーブルに登録するアプリを作成しています。
新規登録画面(app/view/pc/new.html.haml)に遷移しようとするとエラーが発生します。
どのように修正すればよろしいでしょうか。
よろしくお願いします。

#app/view/pc/new.html.haml

= render "shared/header" # ヘッダー呼び出し .new .content = form_with model: @pcs, local:true, class:"wrapper" do |f| .pc .name = f.text_field :name, class:"pc_name", placeholder: "PC名", maxlength: "20",required: true .cpu = f.collection_select :cpu_id, Cpu.all.order(name: :asc), :id, :name .mother_board = f.collection_select :mother_board_id, MotherBoard.all.order(name: :asc), :id, :name .memory = f.collection_select :memory_id, Memory.all.order(name: :asc), :id, :name .videocard = f.collection_select :videocard_id, Videocard.all.order(name: :asc), :id, :name .pc_case = f.collection_select :pc_case_id, PcCase.all.order(name: :asc), :id, :view_name_and_color .power_unit = f.collection_select :power_unit_id, PowerUnit.all.order(name: :asc), :id, :name .ssd = f.collection_select :ssd_id, Ssd.all.order(name: :asc), :id, :name .cpu_cooler = f.collection_select :cpu_cooler_id, CpuCooler.all.order(name: :asc), :id, :name .private %input{name: "private", type: "checkbox", value: "1"} %label{for: "private"} 公開する .submit = f.submit :name, class:"content__wrapper__confirmation__button", value: "確認" = render "shared/footer" # フッター呼び出し

#app/controller/pc_controller.rb

class PcController < ApplicationController before_action :authenticate_user!, except: [:index,:show] def index @pcs = Pc.all end def show @pcs = Pc.find(params[:id]) end def new @pcs = Pc.new end def create @pcs = Pc.new(pc_params) respond_to do |format| if @pcs.save format.html { redirect_to @pcs, notice: '作成成功' } format.json { render :show, status: :created, location: @pcs } else format.html { render :new } end end end def edit @pcs = Pc.find(params[:id]) if current_user.id == @pcs.user.id else redirect_to pc_path(@pcs) end end def update @pcs = Pc.find(params[:id]) if @pcs.update(pc_params) redirect_to pc_path(@pcs) else render :edit end end def destroy pcs = Pc.find(params[:id]) unless pcs.destroy render :show end end end

#config/routes.rb

Rails.application.routes.draw do root 'top#index' devise_for :users, :controllers => { :registrations => 'users/registrations', :sessions => 'users/sessions' } devise_scope :user do get "user/:id", :to => "users/registrations#detail" get "signup", :to => "users/registrations#new" get "login", :to => "users/sessions#new" get "logout", :to => "users/sessions#destroy" end resources :pc, only: [:index, :new, :show, :create, :destroy] resources :cpu, only: [:index, :show] resources :mother_board, only: [:index, :show] resources :memory, only: [:index, :show] resources :videocard, only: [:index, :show] resources :pc_case, only: [:index, :show] resources :power_unit, only: [:index, :show] resources :ssd, only: [:index, :show] resources :cpu_cooler, only: [:index, :show] end

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

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

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

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

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

guest

回答1

0

エラーがでるというならそのエラーメッセージを読み、何故そのエラーが出てるのかを考えましょう。

理由なしにエラーが出てるわけではないです

NoMethodError

そのメソッドが無い、というエラーです。
なぜ無いんでしょうか。

投稿2020/04/28 03:14

y_waiwai

総合スコア87719

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

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

adonson

2020/04/29 01:55

routes.rbにnewがPOSTメソッドを持つように記載してると思いますが、 なぜそれが持っていないことになるのでしょうか。
y_waiwai

2020/04/29 02:04 編集

どこでどういうふうにそのエラーが出るのか提示しましょう。 なにも情報を出さないのに教えろと言われてもムリです エラーメッセージは、無駄な省略翻訳しないで、出たそのママをコピペで提示しましょう
adonson

2020/04/29 03:22

エラー画像をそのままスクリーンショットで追加しました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問