Sorry that last post came across as a little snarky, wasn't how I intended it.
On Wednesday, April 24, 2013 5:54:12 PM UTC+10, Michael Webb wrote: > > Actually Ben, if you look at the examples cited in those links, you'd see > that they're suggesting that the exact situation I have been describing > should "just work". > > On Wednesday, April 24, 2013 5:45:15 PM UTC+10, Ben Taylor wrote: >> >> The big difference is that you're namespacing your models. Without the >> model namespacing it would "just work". >> >> - Ben >> >> On Wednesday, 24 April 2013 at 5:18 PM, Michael Webb wrote: >> >> Thanks Pat, will do. It is a bit of a pain when you're using the same >> form for :new and :edit cause then you're stuck with ternary ifs all up in >> your form_fors, but, if that's how Rails rolls, who am I to argue? >> >> It's a bit bewildering as there are several suggestions that this should >> "just work": >> >> http://stackoverflow.com/questions/2718059/nested-resources-in-namespace-form-for >> >> >> http://stackoverflow.com/questions/4909988/rails-3-nested-resource-route-problem-as-form-for >> >> https://github.com/rails/rails/issues/9146 >> >> On Wednesday, April 24, 2013 5:13:16 PM UTC+10, Pat Allan wrote: >> >> Ben's suggestions are spot on - if your models are namespaced, then the >> namespace is part of the generated route name. >> >> You could probably work around this (see ActiveModel::Naming, which is >> included in ActiveRecord::Base), but personally I would just specify the >> url manually instead - sometimes it's not worth fighting Rails' opinions >> (and it could be that changing the model_name class method could result in >> complications elsewhere). >> >> So: >> >> form_for @charge_rate, :url => >> reconciliation_charge_charge_rates_path(@charge, @charge_rate), #… >> >> If you find yourself writing it a lot, I guess you could wrap it up in a >> helper. >> >> -- >> Pat >> >> On 24/04/2013, at 9:00 AM, Ben Taylor wrote: >> >> > I don't have a complete understanding here, but from what I'm seeing >> I'm assuming that the way the URL is determined from a form_for takes into >> account the objects type. So you have: >> > >> > [:reconciliation, Reconciliation::Charge, Reconciliation::ChargeRate] >> > >> > which rails is deciding should make a URL that looks like... >> > >> > ["reconciliation", "reconciliation_charge", >> "reconiciliation_charge_rate"] >> > >> > when what you actually want is >> > >> > ["reconciliation", "charge", "charge_rate"] >> > >> > I've never namespaced my models, so I've never personally come across >> this. If you are okay with a fix that changes your models, you could remove >> the namespacing from your models and that would fix it. >> > >> > Looking at StackOverflow all I can see is a recommendation to specify >> the URL yourself. >> http://stackoverflow.com/questions/11713427/form-for-with-module-and-namespace >> > >> > Does that help? >> > >> > - Ben >> > >> > On Wednesday, 24 April 2013 at 3:34 PM, Michael Webb wrote: >> > >> >> Hi all, >> >> >> >> I'm building a fairly large Rails app for my current client and am >> doing a bit of a restructure of the database after a manic few months >> getting version one up and running. >> >> >> >> I've tried to group tables into namespaces based on functionality and >> am having some serious difficulty getting form_for to work when it is >> operating on nested resources within a namespace. >> >> >> >> From routes.rb: >> >> ... >> >> namespace :reconciliation do >> >> resources :charges do >> >> resources :charge_rates >> >> end >> >> end >> >> ... >> >> >> >> From the relevant _form.html: >> >> = form_for [:reconciliation, @charge, @charge_rate], :html => >> {:multipart => true, :class => "edit_form"} do |f| >> >> ... >> >> >> >> The line above raises: undefined method >> `reconciliation_reconciliation_charge_reconciliation_charge_rates_path' for >> #<#<Class:0x3758100>:0x3778080> in polymorphic_url. >> >> >> >> I have verified that both @charge and @charge_rate are not null and >> are of the appropriate type (Reconciliation::Charge and >> Reconciliation::ChargeRate). >> >> >> >> rake routes shows that the reconciliation_charge_charge_rates_path >> exists. >> >> >> >> According to every article I could find on Stack Overflow, my >> _form.html code should work, what am I doing wrong? >> >> >> >> Thanks, >> >> >> >> Mike >> >> >> >> -- >> >> You received this message because you are subscribed to the Google >> Groups "Ruby or Rails Oceania" group. >> >> To unsubscribe from this group and stop receiving emails from it, send >> an email to [email protected]. >> >> To post to this group, send email to [email protected]. >> >> Visit this group at http://groups.google.com/group/rails-oceania?hl=en >> . >> >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> >> >> > >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups "Ruby or Rails Oceania" group. >> > To unsubscribe from this group and stop receiving emails from it, send >> an email to [email protected]. >> > To post to this group, send email to [email protected]. >> > Visit this group at http://groups.google.com/group/rails-oceania?hl=en. >> > For more options, visit https://groups.google.com/groups/opt_out. >> > >> > >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby or Rails Oceania" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/rails-oceania?hl=en. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> >> >> -- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/rails-oceania?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
