Reputation: 89
I am pretty new to coding, so I decided to start the Ruby on Rails guide for version 4.0.0 and have had problem after problem. I am currently running version 4.0.0 and I have followed the guide step by step.
Once I got to 5.2 First form I began to get errors and was using other people's posts to solve my questions, but this error doesn't seem to happen for anyone else, so here it is:
NoMethodError in PostsController#index
undefined method `action' for PostsController(Table doesn't exist):Class
Here is my code:
class PostsController < ActiveRecord::Base
attr_accessible :title, :text
def new
end
def create
@post = Post.new(params[:post].permit(:title, :text))
@post.save
redirect_to @post
end
def show
@post = Post.find(params[:id])
end
def index
@post = Post.all
end
def action
end
private
def post_params
params.require(:post).permit(:title, :text)
end
end
Here is my view:
<p>
<strong> Title: </strong>
<%= @post.title %>
</p>
<p>
<strong> Text: </strong>
<%= @post.text %>
</p>
My form is:
<h1> New Post </h1>
<%= form_for :posts, url: posts_path do |f| %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>
<p>
<%= f.label :text%><br>
<%= f.text_area :text %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
The error states that I don't have an action method defined, but I'm not sure how to define one in the first place, however this is not all. When I go to my localhost:3000/posts/new page I get the same error but for PostsController#new
Can someone please help me!!
Upvotes: 6
Views: 8405
Reputation: 211610
It's not clear why your controller is inheriting from a model class:
class PostsController < ApplicationController
# ...
end
Upvotes: 21