2

このエラーが発生し続けますが、理由がわかりません。私は数え切れないほどの時間を検索し、トラブルシューティングを行ってきました。他の投稿サイトに私の問題をチェックしてもらいましたが、解決することさえできません. 助けてください。

エラー:

NoMethodError in Statuses#new

Showing /var/lib/stickshift/51c8b66b5973cac7c2000059/app-root/data/456597/app/views/statuses/_form.html.erb where line #19 raised:

undefined method `content' for #<Status id: nil, created_at: nil, updated_at: nil, user_id: nil>
Extracted source (around line #19):

16:   </div>
17: 
18:    <%= f.input :user_id, collections: User.all, label_method: :full_name %>
19:    <%= f.input :content %>
20:   <div class="form-actions">
21:     <%= f.button :submit %>
22:   </div>
Trace of template inclusion: app/views/statuses/new.html.erb

Rails.root: /var/lib/stickshift/51c8b66b5973cac7c2000059/app-root/data/456597

Application Trace | Framework Trace | Full Trace
app/views/statuses/_form.html.erb:19:in `block in _app_views_statuses__form_html_erb__1439688890277572820_15629600'
app/views/statuses/_form.html.erb:1:in `_app_views_statuses__form_html_erb__1439688890277572820_15629600'
app/views/statuses/new.html.erb:3:in `_app_views_statuses_new_html_erb___4558354498189940408_70153195258980'
app/controllers/statuses_controller.rb:29:in `new'
Request

Parameters:

None
Show session dump

Show env dump

Response

Headers:

None

アプリ/モデル/status.rb

class Status < ActiveRecord::Base
  attr_accessible :content, :user_id
  belongs_to :user
end

アプリ/ビュー/ステータス/_form.html.erb

class StatusesController < ApplicationController
  # GET /statuses
  # GET /statuses.json
  def index
    @statuses = Status.all

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

  # GET /statuses/1
  # GET /statuses/1.json
  def show
    @status = Status.find(params[:id])

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

  # GET /statuses/new
  # GET /statuses/new.json
  def new
    @status = Status.new

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

  # GET /statuses/1/edit
  def edit
    @status = Status.find(params[:id])
  end

  # POST /statuses
  # POST /statuses.json
  def create
    @status = Status.new(params[:status])

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

  # PUT /statuses/1
  # PUT /statuses/1.json
  def update
    @status = Status.find(params[:id])

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

  # DELETE /statuses/1
  # DELETE /statuses/1.json
  def destroy
    @status = Status.find(params[:id])
    @status.destroy

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

config/routes.rb

MGN::Application.routes.draw do
  devise_for :users

  resources :statuses
  root to: 'statuses#index'


  # The priority is based upon order of creation:
  # first created -> highest priority.

  # Sample of regular route:
  #   match 'products/:id' => 'catalog#view'
  # Keep in mind you can assign values other than :controller and :action

  # Sample of named route:
  #   match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
  # This route can be invoked with purchase_url(:id => product.id)

  # Sample resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Sample resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Sample resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Sample resource route with more complex sub-resources
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', :on => :collection
  #     end
  #   end

  # Sample resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end

  # You can have the root of your site routed with "root"
  # just remember to delete public/index.html.
  # root :to => 'welcome#index'

  # See how all your routes lay out with "rake routes"

  # This is a legacy wild controller route that's not recommended for RESTful applications.
  # Note: This route will make all actions in every controller accessible via GET requests.
  # match ':controller(/:action(/:id))(.:format)'
end

アプリ/ビュー/ステータス/_form.html.erb

<%= simple_form_for(@status, html: {class: "form-horizontal"}) do |f| %>
  <% if @status.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@status.errors.count, "error") %> prohibited this status from being saved:</h2>

      <ul>
      <% @status.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">

  </div>

   <%= f.input :user_id, collections: User.all, label_method: :full_name %>
   <%= f.input :content %>
  <div class="form-actions">
    <%= f.button :submit %>
  </div>
<% end %>

これらはすべて、私を助けてくれた以前の人々が求めていたものです。どうすればいいのかわからず、希望を失っています。:(それが役立つ場合は、deviseというgemをインストールしているときにエラーが発生しました。deviseをインストールしたときにデータベースを移行できなかったので、問題だったテーブルを削除しました.ステータステーブル.チュートリアルリンク

4

1 に答える 1

0

エラーメッセージによると:

undefined method `content' for #<Status id: nil, created_at: nil, updated_at: nil, user_id: nil>

contentテーブルに列を追加する移行を作成する必要がありstatusesます。

すでにそのような移行がある可能性があるので、実行rake db:migrateして実行する必要があります。

于 2013-07-03T16:35:47.540 に答える