0

I have a model Post:

class Post < ActiveRecord::Base
  has_one :draft, class_name: Post, foreign_key: draft_id
end

In routes.rb I have the following:

namespace :admin do
  resources :posts do
    resource :draft
  end
end

What I want to achieve is to enable drafts when using form_for, i.e.:

= form_for [:admin, @post, @draft] do |form|

...where @post and @draft are different instances of the same model.

Right now if I do that, I get an error:

NoMethodError: undefined method `admin_tour_tour_url'

Question: So how do I make the form generate admin_tour_draft_url + with a needed modifiers like edit_ and new_?

P.S. am I going the wrong path here?

oldhomemovie
  • 14,621
  • 13
  • 64
  • 99

1 Answers1

1

specify your own path in the form_tag helper by extracting the route explicitly from your routes:

1) rake routes | grep admin_posts

2) notice the path.. probably something like 'admin_posts_draft'

3) add '_path' to the path and that is the name of your helper.. use that helper in your code

<%= form_tag admin_posts_draft_path(@post, @draft) %>
<% end %>
ilan berci
  • 3,883
  • 1
  • 16
  • 21