Nested resources in namespace form_for

前端 未结 3 1832
南方客
南方客 2020-12-08 09:53

Problem

The form_for helper incorrectly determines the path to my nested resource inside of a namespace. The models in question are: Forum::

3条回答
  •  -上瘾入骨i
    2020-12-08 10:47

    @Douglas: It's not working for me. In my view, the names in routes should be pluralize. When I do like recommended, the error is:

    undefined method `admin_admin_person_admin_image_path' for #<#:0x55a9bc8>
    

    My solution that worked for New:

    form_for @image, url: admin_person_images_path(@person, @image)
    

    My solution that worked for Edit:

    form_for @image, url: admin_person_image_path(@person, @image)
    

    Ist there any solution to combine this in one form?

    Edit (Solution for a new nested namespaced route in a form):
    Now I had the following logic in the routes.rb

    resources :mobile_users do
     namespace :candystore do
      resource :transactions
     end
    end
    

    The form for new_mobile_user_candystore_transactions is

    <%= form_for [@mobile_user], url: mobile_user_candystore_transactions_path(@mobile_user), method: :post do |f| %>
    

    to get to the Candystore::TransactionsController create method and not to e.g the MobileUser create method or Candystore::TransactionsController update method.

提交回复
热议问题