I am using STI in my rails app:
class Project < ActiveRecord::Base
end
class Video < Project
end
I've got the following routes:
resources :projects
resources :videos, :controller => "projects", :type => "video"
And when I rake my routes I see that I should be able to POST to /videos:
POST /videos(.:format) projects#create {:type=>"video"}
However, when I visit /videos/new, I notice that the form posts to /projects
= form_for(@project) do |f|
... creates the following HTML ...
<form action="/projects" method="post" >
<!-- ommited -->
</form
My new action in projects_controller looks like this:
def new
@project = params[:type].capitalize.constantize.new
end
def create
@project = params[:type].capitalize.contstantize.new(project_params)
end
I want it to post to /videos and not /projects, because params[:type] is always set to "video" when we are on urls that start with /videos, whereas it's not set to anyything when we are on urls that start with /projects.
UPDATE:
I have a temporary fix:
= f.hidden_field :type
Does the trick when url changes to /projects, but I'd rather have the form post to /videos...