Each project can have a single page:
resources :project do
resource :page
end
class Project < ActiveRecord::Base
has_one :page
end
class Page < ActiveRecord::Base
belongs_to :project
end
def new
@project = Project.find(params[:project_id])
@page = @project.build_page
respond_to do |format|
format.html
end
end
def create
@project = Project.find(params[:project_id])
@page = @project.build_page(params[:page_id])
respond_to do |format|
if @page.save
format.html { redirect_to @page, :notice => 'Page was successfully created.' }
else
format.html { render action: "new" }
end
end
end
But when I go to save a page, I not only get a routing error, but it doesn't actually save to the db.
Routing Error
No route matches [POST] "/projects/2/pages"
My form action looks like this:
<%= form_for([@job, @page]) do |f| %>
Does anyone have any idea of what is going on? I kind of pieced all of this together from other SO posts, but the more I change a line here or there, I feel like I'm getting further from a working solution. For example, if I change the form action to be:
<%= form_for @page, url: job_page_path(@job) do |f| %>
Everything magically works, but then the edit action is still broken. What basic concept am I butchering?
Thanks! --Mark