0
votes

i am getting "undefined method 'new' for Project:Module

My projects_controller.rb class ProjectsController < ApplicationController

def new
    @project = Project.new
end

def create
    @project = Project.new(project_param)
    if @project.save
     redirect_to project_path(@project)
    else
        render 'new'
    end
end

private

    def project_param
        params.require(:projects).permit(:name, :description)
    end

end

my routes

Prefix Verb URI Pattern Controller#Action root GET / pages#home about GET /about(.:format) pages#about help GET /help(.:format) pages#help projects GET /projects(.:format) projects#index POST /projects(.:format) projects#create new_project GET /projects/new(.:format) projects#new edit_project GET /projects/:id/edit(.:format) projects#edit project GET /projects/:id(.:format) projects#show PATCH /projects/:id(.:format) projects#update PUT /projects/:id(.:format) projects#update DELETE /projects/:id(.:format) projects#destroy

pic

1
I'm willing to bet the stacktrace sees your controller but doesn't know what to do with @project = Project.new. Sounds like you have both a module and a class named Project.Anthony
Yes, i do have both named "Project", should i change one or rename the app? I was following along with an instructor as i try to learn.Hodari Toure'
Can you add a repository?Sebastian Palma

1 Answers

0
votes

I just needed to change the params to "params.require(:project)" using the singular instead of the plural.