I'm working my way through the railstutorial whilst working on my own mini project. Whilst it has been suggested that the development database you use should be the same as the one in production, the guide uses sqlite for development and I've been doing the same.
I've deployed some changes recently, that work locally, to my app hosted on Heroku however, when trying to access a specific page, I receive the following error:
If you are the application owner check the logs for more information.
- How can I access the logs that are mentioned?
- I'm guessing a possible cause is due to the code in my controller that returns data from the db, and works in sqlite but is possibly invalid for postgres. Can someone please suggestion improvements for the controller.
I've attached my code below.
accounts_controller.rb:
# GET /accounts/1/history
def history
@account = Account.find(params[:id])
@accountHistory = Account.select("accounts.*, balances.*").joins("JOIN balances").where('balances.account_id = :accountId', {accountId: @account.id}).where('accounts.id = :accountId', {accountId: @account.id}).order('date desc')
end
history.html.erb
<tbody>
<% @accountHistory.each do |a| %>
<tr>
<td><%= date_format(a.date) %></td>
<td class='account-balance'><%= number_to_currency(a.balance, unit: "£") %></td>
</tr>
<% end %>
</tbody>
UPDATE:
Looking at the Heroku logs, it looks like there's a syntax error for Postgres. Can anyone suggest how to improve it?
heroku logs:
2015-12-22T16:54:39.361012+00:00 app[web.1]: Started GET "/accounts/3/history" for 2.220.200.172 at 2015-12-22 16:54:39 +0000
2015-12-22T16:54:39.370975+00:00 app[web.1]: Account Load (0.9ms) SELECT accounts.*, balances.* FROM "accounts" JOIN balances WHERE (balances.account_id = 3) AND (accounts.id = 3) ORDER BY date desc
2015-12-22T16:54:39.371012+00:00 app[web.1]: LINE 1: ...ounts.*, balances.* FROM "accounts" JOIN balances WHERE (bal...
2015-12-22T16:54:39.371010+00:00 app[web.1]: PG::SyntaxError: ERROR: syntax error at or near "WHERE"
2015-12-22T16:54:39.371013+00:00 app[web.1]: ^
2015-12-22T16:54:39.371015+00:00 app[web.1]: : SELECT accounts.*, balances.* FROM "accounts" JOIN balances WHERE (balances.account_id = 3) AND (accounts.id = 3) ORDER BY date desc
2015-12-22T16:54:39.371797+00:00 app[web.1]: Rendered accounts/history.html.erb within layouts/application (2.3ms)
2015-12-22T16:54:39.371929+00:00 app[web.1]: Completed 500 Internal Server Error in 6ms (ActiveRecord: 1.6ms)
2015-12-22T16:54:39.374155+00:00 app[web.1]:
2015-12-22T16:54:39.374158+00:00 app[web.1]: ActionView::Template::Error (PG::SyntaxError: ERROR: syntax error at or near "WHERE"
Aucun commentaire:
Enregistrer un commentaire