###前提・実現したいこと
Rails初心者です。
Rails5で、フォームを作る際、以下のエラーが出て困っております。
どのようにすれば、エラーを解消できるでしょうか?
###発生している問題・エラーメッセージ
NameError in Posts#new undefined local variable or method `f' for #<#<Class:0x007fb64976b1d0>:0x007fb64a1324c0>
###該当のソースコード
ruby
1#View 2<%= form_for @post,:url => {:action => :create} do |p| %> 3 <div class="field"> 4 <%= f.text_area :title %> 5 <%= f.text_field :title, class: 'form-control', placeholder: "タイトル" %><br> 6 <%= f.text_area :content %> 7 <%= f.text_field :content, class: 'form-control', placeholder: "内容" %><br> 8 </div> 9 <div class="actions"> 10 <%= f.submit "登録" %> 11 </div> 12<% end %>
ruby
1#contriller 2class PostsController < ApplicationController 3 def new 4 @post = Post.new 5 end 6 7 def create 8 @post = Post.new(post_params) 9 if @post.save 10 redirect_to '/post' 11 else 12 render 'new' 13 end 14 end 15 16 private 17 18 def post_params 19 params.require(:post).permit(:title, :content) 20 end 21end
ruby
1#routes 2Rails.application.routes.draw do 3 get "post/index" => "posts#index" 4 get "post/new" => "posts#new" 5 post "post/create" => "posts#create" 6end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/07 09:04