1

Railsアプリを作成していますが、これがエラーです。

> NoMethodError in Posts#index

Showing C:/Users/Corey/Dev/statlog/app/views/posts/_form.html.erb where line #1 raised:

undefined method `post_post_post_path' for #<#<Class:0x38109f0>:0x2c54c58>
Extracted source (around line #1):

1: <%= form_for(@posts) do |f| %>
2:   <div class="field">
3:     <h2><%= f.label 'So, hows it going?', :class => 'nuvo' %></h2><br />
4:     <%= f.text_area :status, :class => 'status-update' %>
Trace of template inclusion: app/views/posts/index.html.erb

Rails.root: C:/Users/Corey/Dev/statlog

Application Trace | Framework Trace | Full Trace
app/views/posts/_form.html.erb:1:in `_app_views_posts__form_html_erb___639176493_28084632'
app/views/posts/index.html.erb:10:in `_app_views_posts_index_html_erb___134739565_23263596'
app/controllers/posts_controller.rb:7:in `index'
Request

Parameters:

None
Show session dump

Show env dump

Response

Headers:

None

私の posts_controller は次のとおりです。

class PostsController < ApplicationController
  # GET /posts
  # GET /posts.json
  def index
    @posts = Post.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @posts }
    end
  end

  # GET /posts/1
  # GET /posts/1.json
  def show
    @post = Post.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @post }
    end
  end

  # GET /posts/new
  # GET /posts/new.json
  def new
    @post = Post.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @post }
    end
  end

  # GET /posts/1/edit
  def edit
    @post = Post.find(params[:id])
  end

  # POST /posts
  # POST /posts.json
  def create
    @post = Post.new(params[:post])

    respond_to do |format|
      if @post.save
        format.html { redirect_to @post, notice: 'Post was successfully created.' }
        format.json { render json: @post, status: :created, location: @post }
      else
        format.html { render action: "new" }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /posts/1
  # PUT /posts/1.json
  def update
    @post = Post.find(params[:id])

    respond_to do |format|
      if @post.update_attributes(params[:post])
        format.html { redirect_to @post, notice: 'Post was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /posts/1
  # DELETE /posts/1.json
  def destroy
    @post = Post.find(params[:id])
    @post.destroy

    respond_to do |format|
      format.html { redirect_to posts_url }
      format.json { head :no_content }
    end
  end
end

そして最後に、私の _form.html.erb は次のとおりです。

<%= form_for(@posts) do |f| %>
  <div class="field">
    <h2><%= f.label 'So, hows it going?', :class => 'nuvo' %></h2><br />
    <%= f.text_area :status, :class => 'status-update' %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

本当!誰かが助けてくれることを願っています! また、これは正常に機能していましたが、コンソールを使用して新しい投稿 :status を追加すると、めちゃくちゃになり始めました! 助けてください!

〜CoreyPizzle

4

1 に答える 1