undefined method 'projects_path'
Tearing my hair out here. I have a brand model, this has_many projects and
the projects belong_to the brand. I'm trying to create projects inside the
brand but I'm running into the following error:
undefined method `projects_path'
Everything seems to be in order. Some of my code can be found below:
Routes
resources :brands do
resources :projects do
resources :ideas
end
end
Brands
<%= link_to 'Create New Project', new_brand_project_path(@brand) %>
The routing is working, as the link I'm sent to is
brand/brand_id/projects/new - but this is where I get the error I
mentioned earlier.
Update - The original problem was fixed, now when I save the project I'm
getting the same error, but this time something is wrong with 'create'...
class ProjectsController < ApplicationController
# GET /projects
# GET /projects.json
def index
@projects = Project.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @projects }
end
end
# GET /projects/1
# GET /projects/1.json
def show
@project = Project.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @project }
end
end
# GET /projects/new
# GET /projects/new.json
def new
@brand = Brand.find(params[:brand_id])
@project = Project.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @project }
end
end
# GET /projects/1/edit
def edit
@project = Project.find(params[:id])
end
# POST /projects
# POST /projects.json
def create
@project = Project.new(params[:project])
respond_to do |format|
if @project.save
format.html { redirect_to @project, notice: 'Project was
successfully created.' }
format.json { render json: @project, status: :created, location:
@project }
else
format.html { render action: "new" }
format.json { render json: @project.errors, status:
:unprocessable_entity }
end
end
end
No comments:
Post a Comment