I read a book called 'Rails 3 in Action' and made two pages: 'index' and 'new', set routes.rb:
root :to => 'projects#index'
match '/new', to:'projects#new'
and projects_controller:
def new
@project = Project.new
end
def create
@project = Project.new(parmas[:project])
@project.save
flash[:notice] = "Project has been created"
redirect_to @project
end
and view files:
index.html.erb
<%= link_to "new", new_path %>
This works correctly, because I end up at localhost:3000/new
, but the problem is:
<%= form_for(@project) do |f| %>
This results in:
undefined method `projects_path' for #<#:0x416b830>
Where is projects_path? When I print <%= root_path %>
, I get /
, but <%= projects_path %>
gives error undefined method.
How do I define a method projects_path
? Root is not projects_path
?