我將Rails應用程序從3.2.13遷移到4.0.0,但在運行應用程序時,出現錯誤:/signup.html中的NoMethodError未定義的方法`each'for nil:NilClass while running Rails application
Started GET "/signup.html" for 127.0.0.1 at 2016-06-29 17:28:16 +0530 ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations" Processing by AccountsController#new as HTML Parameters: {"plan"=>"year"} Completed 500 Internal Server Error in 51ms ** [Airbrake] Notice was not sent due to configuration: Environment Monitored? false API key set? true
NoMethodError - undefined method
each' for nil:NilClass:
initialize' app/controllers/accounts_controller.rb:83:in
activemerchant (1.47.0) lib/active_merchant/billing/model.rb:11:inload_billing' activesupport (4.0.0) lib/active_support/callbacks.rb:437:in
_run__3203841093432473566__process_action__callbacks' activesupport (4.0.0) lib/active_support/callbacks.rb:80:inrun_callbacks'
process_action' actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in
.......................................
這是我的控制器代碼:
class AccountsController < ApplicationController
#inherit_resources
ssl_required :new, :create
before_filter :load_billing, :only => [:new, :create]
def new
@account_name = Rails.application.config.custom.accounts.send(params[:account_name]).name
@account_signup_message = Rails.application.config.custom.accounts.send(params[:account_name]).signup_message
rescue
nil
end
def create
@address.first_name = @creditcard.first_name
@address.last_name = @creditcard.last_name
@account.address = @address
@account.creditcard = @creditcard
if @account.new_record?
if @account.save
flash[:notice] = 'Account was created.'
sign_in(@user, :bypass => true)
redirect_to session[:previous_url] || user_reports_path(@user)
else
render :action => 'new'
end
else
@user.account_id = @account.id
if @user.save
flash[:notice] = 'User was created.'
sign_in(@user, :bypass => true)
redirect_to session[:previous_url] || user_reports_path(@user)
else
render :action => 'new'
end
end
end
protected
def load_billing
@creditcard = ActiveMerchant::Billing::CreditCard.new(params[:account].blank? ? nil : params[:account][:creditcard]) #This is the line it is showing error.
@address = SubscriptionAddress.new(params[:account].blank? ? nil : params[:account][:address])
end
end
的routes.rb:
get '/signup' => 'accounts#new'
賬戶/ new.html.erb:
<%= semantic_form_for(@account, :url => account_create_path, :html => { :multipart => true, :class => 'billing'}) do |f| %>
<%= f.inputs :for => :user do |u| %>
#name and email fields are mentioned.
<% end %>
<%= f.inputs :for => :creditcard do |c| %>
#name, card_no, cvv, expire_date etc;
<% end %>
<% end %>
這是我的activemerchant(1.47.0)LIB/active_merchant /計費/ model.rb:
require "active_merchant/billing/compatibility"
require "active_merchant/empty"
module ActiveMerchant
module Billing
class Model
include Compatibility::Model
include Empty
def initialize(attributes = {})
attributes.each do |key, value|
send("#{key}=", value)
end
end
def validate
{}
end
private
def errors_hash(array)
array.inject({}) do |hash, (attribute, error)|
(hash[attribute] ||= []) << error
hash
end
end
end
end
end
包括空在上述代碼中的錯誤顯示線。並且沒有model.rb文件用於activemerchant版本1.20.4(我的以前)。 請幫幫我。
從看你的錯誤信息我可以告訴問題是在lib/active_merchant/billing/model.rb:11上的回調。在那條線上,不管你打給誰,每個人都不存在。如果您仍然感到困惑,請從該文件發佈代碼 –
我在問題中已更新。請檢查。 – user3189916