带有 ActiveMerchant 和 Rails 3 的信用卡表格
Posted
技术标签:
【中文标题】带有 ActiveMerchant 和 Rails 3 的信用卡表格【英文标题】:Credit Card form with ActiveMerchant and Rails 3 【发布时间】:2011-07-03 18:32:16 【问题描述】:使用 Rails 3,我无法使用 ActiveMerchant::Billing::CreditCard.new 获得表单。
控制器
@credit_card = ActiveMerchant::Billing::CreditCard.new
查看
<%= form_for :credit_card, @credit_card do |f| %>
<%= f.text_field :first_name %>
<% end %>
错误
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.any?
actionpack (3.0.4) lib/action_view/helpers/active_model_helper.rb:62:in `object_has_errors?'
actionpack (3.0.4) lib/action_view/helpers/active_model_helper.rb:48:in `error_wrapping'
actionpack (3.0.4) lib/action_view/helpers/active_model_helper.rb:44:in `tag'
actionpack (3.0.4) lib/action_view/helpers/form_helper.rb:918:in `to_input_field_tag'
actionpack (3.0.4) lib/action_view/helpers/form_helper.rb:625:in `text_field'
actionpack (3.0.4) lib/action_view/helpers/form_helper.rb:1131:in `send'
actionpack (3.0.4) lib/action_view/helpers/form_helper.rb:1131:in `text_field'
app/views/account/credit_card/edit.html.erb:8:in `_app_views_account_credit_card_edit_html_erb___109645858_2193109920_0'
actionpack (3.0.4) lib/action_view/helpers/capture_helper.rb:40:in `capture'
actionpack (3.0.4) lib/action_view/helpers/capture_helper.rb:172:in `with_output_buffer'
actionpack (3.0.4) lib/action_view/helpers/capture_helper.rb:40:in `capture'
actionpack (3.0.4) lib/action_view/helpers/form_helper.rb:544:in `fields_for'
actionpack (3.0.4) lib/action_view/helpers/form_helper.rb:320:in `form_for'
app/views/account/credit_card/edit.html.erb:7:in `_app_views_account_credit_card_edit_html_erb___109645858_2193109920_0'
actionpack (3.0.4) lib/action_view/template.rb:135:in `send'
actionpack (3.0.4) lib/action_view/template.rb:135:in `render'
activesupport (3.0.4) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.4) lib/action_view/template.rb:127:in `render'
actionpack (3.0.4) lib/action_view/render/rendering.rb:59:in `_render_template'
activesupport (3.0.4) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.4) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.4) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.4) lib/action_view/render/rendering.rb:56:in `_render_template'
actionpack (3.0.4) lib/action_view/render/rendering.rb:26:in `render'
actionpack (3.0.4) lib/abstract_controller/rendering.rb:115:in `_render_template'
actionpack (3.0.4) lib/abstract_controller/rendering.rb:109:in `render_to_body'
actionpack (3.0.4) lib/action_controller/metal/renderers.rb:47:in `render_to_body'
actionpack (3.0.4) lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
actionpack (3.0.4) lib/abstract_controller/rendering.rb:102:in `render_to_string'
actionpack (3.0.4) lib/abstract_controller/rendering.rb:93:in `render'
actionpack (3.0.4) lib/action_controller/metal/rendering.rb:17:in `render'
actionpack (3.0.4) lib/action_controller/metal/instrumentation.rb:40:in `render_without_wicked_pdf'
activesupport (3.0.4) lib/active_support/core_ext/benchmark.rb:5:in `ms'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:308:in `realtime'
activesupport (3.0.4) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.0.4) lib/action_controller/metal/instrumentation.rb:40:in `render_without_wicked_pdf'
actionpack (3.0.4) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.0.4) lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.0.4) lib/action_controller/metal/instrumentation.rb:39:in `render_without_wicked_pdf'
vendor/plugins/wicked_pdf/lib/pdf_helper.rb:15:in `render'
actionpack (3.0.4) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.0.4) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (3.0.4) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.4) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.4) lib/abstract_controller/callbacks.rb:18:in `process_action'
activesupport (3.0.4) lib/active_support/callbacks.rb:485:in `_run__210577272__process_action__1992409046__callbacks'
activesupport (3.0.4) lib/active_support/callbacks.rb:409:in `send'
activesupport (3.0.4) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.4) lib/active_support/callbacks.rb:93:in `send'
activesupport (3.0.4) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.4) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
activesupport (3.0.4) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.4) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.4) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.4) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.4) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.4) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.4) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.4) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.4) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.4) lib/action_controller/metal.rb:178:in `action'
actionpack (3.0.4) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.4) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.4) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:148:in `call'
routing-filter (0.2.3) lib/routing_filter/adapters/rails_3.rb:74:in `recognize'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.4) lib/action_dispatch/routing/route_set.rb:492:in `call'
exception_notification_rails3 (1.2.0) lib/exception_notifier.rb:34:in `call'
warden (1.0.3) lib/warden/manager.rb:35:in `call'
warden (1.0.3) lib/warden/manager.rb:34:in `catch'
warden (1.0.3) lib/warden/manager.rb:34:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.1) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.4) lib/active_record/query_cache.rb:32:in `call'
activerecord (3.0.4) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.4) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.4) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.4) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.4) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.1) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.4) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.4) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `synchronize'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.4) lib/rails/application.rb:168:in `call'
railties (3.0.4) lib/rails/application.rb:77:in `send'
railties (3.0.4) lib/rails/application.rb:77:in `method_missing'
passenger (3.0.2) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
passenger (3.0.2) lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
passenger (3.0.2) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
passenger (3.0.2) lib/phusion_passenger/rack/application_spawner.rb:205:in `start_request_handler'
passenger (3.0.2) lib/phusion_passenger/rack/application_spawner.rb:170:in `send'
passenger (3.0.2) lib/phusion_passenger/rack/application_spawner.rb:170:in `handle_spawn_application'
passenger (3.0.2) lib/phusion_passenger/utils.rb:479:in `safe_fork'
passenger (3.0.2) lib/phusion_passenger/rack/application_spawner.rb:165:in `handle_spawn_application'
passenger (3.0.2) lib/phusion_passenger/abstract_server.rb:357:in `__send__'
passenger (3.0.2) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.2) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.2) lib/phusion_passenger/abstract_server.rb:180:in `start'
passenger (3.0.2) lib/phusion_passenger/rack/application_spawner.rb:128:in `start'
passenger (3.0.2) lib/phusion_passenger/spawn_manager.rb:253:in `spawn_rack_application'
passenger (3.0.2) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
passenger (3.0.2) lib/phusion_passenger/spawn_manager.rb:246:in `spawn_rack_application'
passenger (3.0.2) lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize'
passenger (3.0.2) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
passenger (3.0.2) lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
passenger (3.0.2) lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
passenger (3.0.2) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
passenger (3.0.2) lib/phusion_passenger/abstract_server.rb:357:in `__send__'
passenger (3.0.2) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.2) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.2) helper-scripts/passenger-spawn-server:99
收到此错误时,我没有使用任何表单生成器。有没有其他方法可以做到这一点?
【问题讨论】:
如果有帮助,它在 Rails 2.3.11 下运行良好 你为什么有:credit_card, @credit_card
?不应该只是@credit_card
吗?
仅使用@credit_card 将返回以下“ActiveMerchant::Billing::CreditCard:Class 的未定义方法 `model_name'”
发现问题:github.com/Shopify/active_merchant/issues#issue/30
【参考方案1】:
你可以通过这个破解自己的方式:
https://github.com/Shopify/active_merchant/pull/33
Shopify 团队表示在 ActiveMerchant 2.0 之前不会进行修复
【讨论】:
即使不理想,当前版本的activemerchant实际上是支持rails 3.x 我的问题是由于之前的补丁产生了冲突。 它支持Rails 3,但是在不能在form_for 中使用CreditCard 的情况下,仍然存在这个特定问题。令人沮丧。 我目前确实在 form_for 中使用 CreditCard 没有问题。确保您没有任何正在使用的 active_merchant 补丁(我有一个,以前需要支持 Rails 3,这给了我警告并且不适用于 Rails 3.1+)以上是关于带有 ActiveMerchant 和 Rails 3 的信用卡表格的主要内容,如果未能解决你的问题,请参考以下文章
ruby on rails 1.2.6 和 ActiveMerchant
如何在视图中显示支付网关响应消息 - Rails 4,Active Merchant
在 ActiveMerchant 中测试 Paypal Express
有没有更安全的方法可以同时使用 Stripe 和 ActiveMerchant? Ruby on Rails