2015-12-27 5 views
0

При попытке создать новый ресурс с помощью типичных форм рельсов я получаю undefined method stripe_managed_accounts_path. Ниже мой код, я ошарашен, не могу понять.Odd Rails Routing erros

Контроллер

class StripeManagedAccountsController < ApplicationController 
    before_action :authenticate_printer! 

    def new 
    @stripe_managed_account = StripeManagedAccount.new(printer_id: current_printer.id) 
    end 
end 

модель

class StripeManagedAccount < ActiveRecord::Base 
    belongs_to :printer 
end 

просмотров/новые

<h1>Create New Stripe Managed Account</h1> 

<%= render 'form' %> 

вид/форма

<h5>inside the form</h5> 

<%= form_for @stripe_managed_account do |f| %> 

<% end %> 

маршруты

resources :printers, only: [:show, :edit, :update] do 
    resources :stripe_managed_accounts 
end 

ошибка

`undefined method 'stripe_managed_accounts_path' for #<#<Class:0x007fc627d342b8>:0x007fc62b36e108>` 

маршруты

printer_stripe_managed_accounts GET /printers/:printer_id/stripe_managed_accounts(.:format)   stripe_managed_accounts#index 
            POST /printers/:printer_id/stripe_managed_accounts(.:format)   stripe_managed_accounts#create 
new_printer_stripe_managed_account GET /printers/:printer_id/stripe_managed_accounts/new(.:format)  stripe_managed_accounts#new 
edit_printer_stripe_managed_account GET /printers/:printer_id/stripe_managed_accounts/:id/edit(.:format) stripe_managed_accounts#edit 
    printer_stripe_managed_account GET /printers/:printer_id/stripe_managed_accounts/:id(.:format)  stripe_managed_accounts#show 
            PATCH /printers/:printer_id/stripe_managed_accounts/:id(.:format)  stripe_managed_accounts#update 
            PUT /printers/:printer_id/stripe_managed_accounts/:id(.:format)  stripe_managed_accounts#update 
            DELETE /printers/:printer_id/stripe_managed_accounts/:id(.:format)  stripe_managed_accounts#destroy 

и он highliting эту линию <%= form_for @stripe_managed_account do |f| %>

Я grepped весь базовый код для stripe_managed_accounts_path и не где , Я в конце концов шансов ...

UPDATE :::

Если добавить этот маршрут он исчезает ??? Почему он ищет этот маршрут. Это из-за того, как я назвал свои кормушки и т. Д.?

+0

обеспечивают грабли: маршруты, это может быть ключом –

+0

Я. может быть, это будет – Seal

+0

это интересно '# <# <Класс: 0x007fc627d342b8>: 0x007fc62b36e108>' – Seal

ответ

1

Вы размещаете stripe_managed_accounts внутри printers в вашем файле маршрутов. Если вы посмотрите на вывод rake routes, вы увидите, что нет пути для stripe_managed_accounts_path.

Вы можете использовать мелкую опцию на ресурсе stripe_managed_accounts или настроить форму для включения принтера, к которому будет принадлежать управляемая учетная запись.

#controller 
class StripeManagedAccountsController < ApplicationController 
    before_action :authenticate_printer! 

    def new 
    @stripe_managed_account = current_printer.build_stripe_managed_account 
    end 

    def create 
    current_printer.stripe_managed_accounts.create stripe_managed_account_params 
    # handle response 
    end 

    def stripe_managed_account_params 
    params.require(:stripe_managed_account).permit([list of attributes]) 
    end 
end 

#form 
<h5>inside the form</h5> 

<%= form_for [current_printer, @stripe_managed_account] do |f| %> 

<% end %> 

Это будет генерировать правильный URL, гнездящихся на stripe_managed_account внутри текущего принтера.

Для справки has_one ассоциации http://guides.rubyonrails.org/association_basics.html#has-one-association-reference