2012-08-13 21 views
15

Tôi có một mẫu có tên ActiveDns. Khi tôi chạyĐường ray - Tên mẫu kết thúc bằng S

rails g scaffold_controller ActiveDns 

Tôi nhận được thông báo

phiên bản số nhiều của mô hình phát hiện, sử dụng phiên bản singularized. Ghi đè bằng --force-plural.

Bây giờ, bộ điều khiển và quan điểm được tạo ra giả vờ rằng số ít là ActiveDn và số nhiều là ActiveDns, và tôi nhận được những thứ ngớ ngẩn như link_to new_dn_path. Đối số --force-plural không xuất hiện để sửa lỗi này:

rails g scaffold_controller ActiveDns --force-plural 

vẫn dẫn đến bộ điều khiển sử dụng các biến tên @active_dn và quan điểm sử dụng new_dn_path, với đường ray 3.2.3. Tôi đang xóa các tệp giữa các lần thử sử dụng rails d scaffold_controller ActiveDns.

Cách thích hợp để thực hiện việc này là gì?

+2

Thay vì loại bỏ các tập tin không chính xác bằng tay, bạn có thể cũng chỉ là 'đường ray phá hủy scaffold_controller ActiveDns' –

Trả lời

14

Cách thích hợp để thực hiện việc này là gì?

Tôi sử dụng inflections đến document thực thể không đếm được.

config/initializers/inflections.rb

ActiveSupport::Inflector.inflections do |inflect| 
    inflect.uncountable "ActiveDns" 
end 

Sau đó, bạn nhận được:

$ rails g scaffold_controller ActiveDns 
     create app/controllers/active_dns_controller.rb 
     invoke erb 
     create app/views/active_dns 
     create app/views/active_dns/index.html.erb 
     create app/views/active_dns/edit.html.erb 
     create app/views/active_dns/show.html.erb 
     create app/views/active_dns/new.html.erb 
     create app/views/active_dns/_form.html.erb 
     invoke test_unit 
     create test/functional/active_dns_controller_test.rb 
     invoke helper 
     create app/helpers/active_dns_helper.rb 
     invoke test_unit 
     create  test/unit/helpers/active_dns_helper_test.rb 

Đây có phải là những gì bạn muốn?

11

tôi thử nghiệm với đường ray-3.2 (tôi đoán nó sẽ làm việc với đường ray-3.x)

Mở config/initializers/inflections.rb của bạn và thêm một quy tắc:

ActiveSupport::Inflector.inflections do |inflect| 
    inflect.irregular 'dns', 'dnses' 
end 

Và tạo ra bộ điều khiển

rails g scaffold_controller ActiveDns 

Và thêm tuyến đường vào config/routes.rb của bạn

resources :active_dnses 

Sau đó, bạn sẽ thấy:

$ rake routes 

    active_dnses GET /active_dnses(.:format)   active_dnses#index 
       POST /active_dnses(.:format)   active_dnses#create 
new_active_dns GET /active_dnses/new(.:format)  active_dnses#new 
edit_active_dns GET /active_dnses/:id/edit(.:format) active_dnses#edit 
    active_dns GET /active_dnses/:id(.:format)  active_dnses#show 
       PUT /active_dnses/:id(.:format)  active_dnses#update 
       DELETE /active_dnses/:id(.:format)  active_dnses#destroy 
+0

Tác phẩm tốt cho tôi với đường ray 4.2.1 –

Các vấn đề liên quan