I keep getting this error and I don't know why. I've searched and troubleshooted for countless hours now. I've even had other posting sites check out my problem and they can't even solve it. Please help.
The Error:
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
app/models/status.rb
class Status < ActiveRecord::Base
attr_accessible :content, :user_id
belongs_to :user
end
app/views/status/_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
app/views/statuses/_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 %>
These are all the things previous people helping me asked for. I don't know what to do and I'm losing hope. :( If it helps any the error arose when I was installing a gem called devise. When I installed devise I was unable to migrate my databases so I dropped the table that was the problem. the Statuses table. Tutorial link