当我启动我的应用程序时,我收到以下错误:
Completed 500 Internal Server Error in 9ms
F, [2015-08-11T13:32:09.513613 #10107] FATAL -- :
RuntimeError (You can't use Gon public methods for storing data):
app/controllers/application_controller.rb:228:in `set_gon'
lib/middleware/security.rb:11:in `call'
该错误中提到了第228行。以下是第237行到第237行的内容:
if current_user
gon.current_user = { sn: current_user.sn }
gon.accounts = current_user.accounts.inject({}) do |memo, account|
memo[account.currency] = {
currency: account.currency,
balance: account.balance,
locked: account.locked
} if account.currency_obj.try(:visible)
memo
end
end
以下是整个方法的样子:
def set_gon
gon.env = Rails.env
gon.local = I18n.locale
gon.market = current_market.attributes
gon.ticker = current_market.ticker
gon.markets = Market.to_hash
gon.pusher = {
key: ENV['PUSHER_KEY'],
wsHost: ENV['PUSHER_HOST'] || 'ws.pusherapp.com',
wsPort: ENV['PUSHER_WS_PORT'] || '80',
wssPort: ENV['PUSHER_WSS_PORT'] || '443',
encrypted: ENV['PUSHER_ENCRYPTED'] == 'true'
}
gon.clipboard = {
:click => I18n.t('actions.clipboard.click'),
:done => I18n.t('actions.clipboard.done')
}
gon.i18n = {
brand: I18n.t('gon.brand'),
ask: I18n.t('gon.ask'),
bid: I18n.t('gon.bid'),
cancel: I18n.t('actions.cancel'),
latest_trade: I18n.t('private.markets.order_book.latest_trade'),
switch: {
notification: I18n.t('private.markets.settings.notification'),
sound: I18n.t('private.markets.settings.sound')
},
notification: {
title: I18n.t('gon.notification.title'),
enabled: I18n.t('gon.notification.enabled'),
new_trade: I18n.t('gon.notification.new_trade')
},
time: {
minute: I18n.t('chart.minute'),
hour: I18n.t('chart.hour'),
day: I18n.t('chart.day'),
week: I18n.t('chart.week'),
month: I18n.t('chart.month'),
year: I18n.t('chart.year')
},
chart: {
price: I18n.t('chart.price'),
volume: I18n.t('chart.volume'),
open: I18n.t('chart.open'),
high: I18n.t('chart.high'),
low: I18n.t('chart.low'),
close: I18n.t('chart.close'),
candlestick: I18n.t('chart.candlestick'),
line: I18n.t('chart.line'),
zoom: I18n.t('chart.zoom'),
depth: I18n.t('chart.depth'),
depth_title: I18n.t('chart.depth_title')
},
place_order: {
confirm_submit: I18n.t('private.markets.show.confirm'),
confirm_cancel: I18n.t('private.markets.show.cancel_confirm'),
price: I18n.t('private.markets.place_order.price'),
volume: I18n.t('private.markets.place_order.amount'),
sum: I18n.t('private.markets.place_order.total'),
price_high: I18n.t('private.markets.place_order.price_high'),
price_low: I18n.t('private.markets.place_order.price_low'),
full_bid: I18n.t('private.markets.place_order.full_bid'),
full_ask: I18n.t('private.markets.place_order.full_ask')
},
trade_state: {
new: I18n.t('private.markets.trade_state.new'),
partial: I18n.t('private.markets.trade_state.partial')
}
}
gon.currencies = Currency.all.inject({}) do |memo, currency|
memo[currency.code] = {
code: currency[:code],
symbol: currency[:symbol],
isCoin: currency[:coin]
}
memo
end
gon.fiat_currency = Currency.first.code
gon.tickers = {}
Market.all.each do |market|
gon.tickers[market.id] = market.unit_info.merge(Global[market.id].ticker)
end
if current_user
gon.current_user = { sn: current_user.sn }
gon.accounts = current_user.accounts.inject({}) do |memo, account|
memo[account.currency] = {
currency: account.currency,
balance: account.balance,
locked: account.locked
} if account.currency_obj.try(:visible)
memo
end
end
end
任何人都知道如何解决这个问题?
答案 0 :(得分:0)
当我的代码看起来像这样时,我遇到了同样的错误:
gon.push = ({
article_id: @article.id
})
当我删除'='时全部工作。
gon.push({
article_id: @article.id
})