In the rails guides tutorial creating a blog app after we create the rails app and create a resources in the routes then we start working on a form_for for creating a posts title and text in the guide it tells me that we need to add this line
<%= form_for :post, url: posts_path do |f| %>
the posts_path helper is passed to the :url option. What Rails will do with this is that it will point the form to the create action of the current controller, the PostsController, and will send a POST request to that route.
<h1>Here Lets create a simple post</h1>
<%= form_for :post, url: posts_path do|f| %>
<%= f.label :title %>
<%= f.text_field :title %>
<%= f.submit %>
<% end %>
class PostsController < ApplicationController
@post = Post.new
@post = Post.new(post_params)
<h1>THis is the post create action</h1>
<%= @post.title %>
uninitialized constant PostsController::Post
We generally use Rails to build database-backed applications, but for learning purposes, you can do it this way.
The problem you are facing here is: You are tyring to create an object of the Post class, that will be the model in the example you are referring to. The error comes up since you have not created the Post model.
To meet your requirement you can make your
create action be:
def create @post = post_params #this will be a hash end
Then change your view to:
<h1>THis is the post create action</h1> <%= @post[:title] %>