皆様、質問がございます、よろしくお願い申し上げます。
質問 modelにあるデータを一覧表示したいが、表示されず下記のcreate.html.erbファイルが表示されます。 そのため、どうすればindex.html.erbファイルが表示できるのかご指導下さい 問題点 routes.rbにあるgetメソッドとpostメソッドの対応関係を理解していないため、問題が生じていると考えています。
create.html.erb(現在表示されるファイル) <p><%= @pin.title %></p> <p><%= @pin.description %></p>
PinsController(対応するcontrollerファイル) class PinsController < ApplicationController def new end def create @pin = Pin.new @pin.title = params[:title] @pin.description = params[:description] @pin.save end def index @pins = Pin.all end end
index.html.erb(表示したいファイル) <% @pins.each do |pin| %> <%= pin.title %> <%= pin.description %> <% end %>
routes.rb(ファイルとコントローラの対応関係) PinBoard::Application.routes.draw do get '/pins/new' => 'pins#new' post '/pins' => 'pins#create' get '/pins' => 'pins#index' end
よろしくお願い申し上げます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/09/17 09:28 編集