
Untitled
By: a guest on
May 1st, 2012 | syntax:
None | size: 1.19 KB | hits: 14 | expires: Never
Rails nested routing shallow edit not working
resources :customers do
resources :electricity_counters, :shallow => true do
resources :electricity_bills, :shallow => true
end
end
<%= form_for([@customer, @customer.electricity_counters.build]) do |f| %>
# GET customers/1/electricity_counters/new
def new
@customer = Customer.find(params[:customer_id])
@electricity_counter = @customer.electricity_counters.build
end
# GET /electricity_counters/1/edit
def edit
@electricity_counter = ElectricityCounter.find(params[:id])
@customer = @electricity_counter.customer
end
belongs_to :customer
<%= form_for([@customer, @customer.electricity_counters.build]) do |f| %>
def new
@customer = Customer.find(params[:customer_id])
@electricity_counter = @customer.electricity_counters.build
@path = [@customer, @electricity_counter]
end
def edit
@electricity_counter = ElectricityCounter.find(params[:id])
@customer = @electricity_counter.customer
@path = @electricity_counter
end
<%= form_for(@path) do |f| %>
resources :customers, :shallow => true do
resources :electricity_counters, :shallow => true do
resources :electricity_bills
end
end