gpt4 book ai didi

ruby-on-rails-3 - 编辑表单中单表继承的问题

转载 作者:行者123 更新时间:2023-12-04 06:13:53 24 4
gpt4 key购买 nike

我在 ROR3 中使用单表继承,所以我创建了这些模型:

class Promotion < ActiveRecord::Base

...

end

class CreditPromotion < Promotion
end

class DebitPromotion < Promotion
end

然后我在局部 View 中创建了一个通用表单
<%= form_for([:admin, @promotion]) do |f| %>
#Many fields for promotion
<% end %>

在新 Action 中,这种形式非常有效。但是在编辑操作中抛出此错误消息:
NoMethodError in Admin/promotions#edit

Showing /home/mperez/Proyectos/Habitue/commerce/commerce/app/views/admin/promotions/_form.html.erb where line #48 raised:

undefined method `admin_debit_promotion_path' for #<#<Class:0x7fcf57ada178>:0x7fcf57ad6820>

Extracted source (around line #48):

45: });
46: </script>
47:
48: <%= form_for([:admin, @promotion]) do |f| %>
49: <% if @promotion.errors.any? %>
50: <div id="error_explanation">
51: <h2><%= pluralize(@promotion.errors.count, "error") %> prohibited this promotion from being saved:</h2>

更新:添加路线
Rails3::Application.routes.draw do

# Administration
namespace :admin do
match 'dashboard/update_cities' => 'dashboard#update_cities', :as => :update_cities
match 'dashboard/update_departments' => 'dashboard#update_departments', :as => :update_departments
match 'dashboard/update_towns' => 'dashboard#update_towns', :as => :update_towns
match 'promotions/unlimmited_quota' => 'promotions#unlimmited_quota', :as => :unlimmited_quota
match 'promotions/unlimmited_limit_per_user' => 'promotions#unlimmited_limit_per_user', :as => :unlimmited_limit_per_user

root :to => 'dashboard#index'

resources :settings
match '/settings/update_settings' => 'settings#update_settings', :requirements => { :method => :post }
resources :announcements
resources :commits
resources :sellers
resources :commerces
resources :commerce_visits
resources :promotions do
collection do
post :load_promotion_fields
end
end

#resources :debit_promotions, :controller => :promotions
#resources :credit_promotions, :controller => :promotions
#resources :gift_promotions, :controller => :promotions

resources :store_points

match '/users/search' => 'users#search', :requirements => { :method => :get }

resources :users do
member do
put :suspend
put :unsuspend
put :activate
delete :purge
put :reset_password
get :set_user_login
get :set_user_email
end
collection do
get :pending
get :active
get :suspended
get :deleted
end
end
end
end

哪个可能是问题?

我了解路线有问题。但是我不想改变它。

如何使用具有一般形式的单表继承?

提前致谢

最佳答案

当您编辑促销时,它已经被实例化为 DebitPromotion。

form_for([:admin, @promotion])

尝试转到不存在的 admin_debit_promotion_path(@promotion)

因此,覆盖它以转到正确的路由和 Controller ,如下所示:
form_for([:admin, @promotion], :url => admin_promotion_path(@promotion))

关于ruby-on-rails-3 - 编辑表单中单表继承的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7489073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com