This works locally, but not in heroku.
I have tried migrating locally, then pushing to heroku it did not work. I have tried heroku run rake db:migrate, then restarting it did not work.
I have tried to restart the dyno, it also did not work.
Is there something I can check which would give more detail? I was looking at heroku run rake db:migrate:status, but it only shows the general migration create books.
Error:
2017-09-20T21:31:06.432739+00:00 app[web.1]: I, [2017-09-20T21:31:06.432588 #4] INFO -- : [f953f5f7-3cab-45a4-9f97-2cd7004e2807] Started GET "/books" for 81.106.178.87 at 2017-09-20 21:31:06 +0000
2017-09-20T21:31:06.441798+00:00 app[web.1]: I, [2017-09-20T21:31:06.441609 #4] INFO -- : [f953f5f7-3cab-45a4-9f97-2cd7004e2807] Rendering books/index.html.erb within layouts/application
2017-09-20T21:31:06.435519+00:00 app[web.1]: I, [2017-09-20T21:31:06.435371 #4] INFO -- : [f953f5f7-3cab-45a4-9f97-2cd7004e2807] Processing by BooksController#index as HTML
2017-09-20T21:31:06.487993+00:00 app[web.1]: D, [2017-09-20T21:31:06.487768 #4] DEBUG -- : [f953f5f7-3cab-45a4-9f97-2cd7004e2807] Book Load (4.1ms) SELECT "books".* FROM "books"
2017-09-20T21:31:06.549929+00:00 app[web.1]: I, [2017-09-20T21:31:06.549786 #4] INFO -- : [f953f5f7-3cab-45a4-9f97-2cd7004e2807] Rendered books/index.html.erb within layouts/application (107.8ms)
2017-09-20T21:31:06.550338+00:00 app[web.1]: I, [2017-09-20T21:31:06.550261 #4] INFO -- : [f953f5f7-3cab-45a4-9f97-2cd7004e2807] Completed 500 Internal Server Error in 115ms (ActiveRecord: 22.9ms)
2017-09-20T21:31:06.552408+00:00 app[web.1]: F, [2017-09-20T21:31:06.552334 #4] FATAL -- : [f953f5f7-3cab-45a4-9f97-2cd7004e2807]
2017-09-20T21:31:06.552538+00:00 app[web.1]: F, [2017-09-20T21:31:06.552475 #4] FATAL -- : [f953f5f7-3cab-45a4-9f97-2cd7004e2807] ActionView::Template::Error (undefined method `author' for #<Book:0x00000003849768>):
2017-09-20T21:31:06.552872+00:00 app[web.1]: [f953f5f7-3cab-45a4-9f97-2cd7004e2807] 24: <tr>
2017-09-20T21:31:06.552875+00:00 app[web.1]: [f953f5f7-3cab-45a4-9f97-2cd7004e2807] 27: <td><%= image_tag book.image_url.to_s%></td>
2017-09-20T21:31:06.552870+00:00 app[web.1]: F, [2017-09-20T21:31:06.552781 #4] FATAL -- : [f953f5f7-3cab-45a4-9f97-2cd7004e2807] 23: <% @books.each do |book| %>
2017-09-20T21:31:06.552873+00:00 app[web.1]: [f953f5f7-3cab-45a4-9f97-2cd7004e2807] 25: <td><%= book.name %></td>
2017-09-20T21:31:06.552874+00:00 app[web.1]: [f953f5f7-3cab-45a4-9f97-2cd7004e2807] 26: <td><%= book.author %></td>
2017-09-20T21:31:06.552876+00:00 app[web.1]: [f953f5f7-3cab-45a4-9f97-2cd7004e2807] 28: <td><%= link_to "Свали Книга", book.attachment_url %></td>
2017-09-20T21:31:06.552881+00:00 app[web.1]: [f953f5f7-3cab-45a4-9f97-2cd7004e2807] 29: <td><%= button_to "Delete", book, method: :delete, class: "btn btn-danger", confirm: "Сигурни ли сте, че желаете да изтриете #{book.name}?" %></td>
2017-09-20T21:31:06.552931+00:00 app[web.1]: F, [2017-09-20T21:31:06.552862 #4] FATAL -- : [f953f5f7-3cab-45a4-9f97-2cd7004e2807]
2017-09-20T21:31:06.553046+00:00 app[web.1]: F, [2017-09-20T21:31:06.552958 #4] FATAL -- : [f953f5f7-3cab-45a4-9f97-2cd7004e2807] app/views/books/index.html.erb:26:in `block in _app_views_books_index_html_erb__879124352395591768_27663240'
2017-09-20T21:31:06.553047+00:00 app[web.1]: [f953f5f7-3cab-45a4-9f97-2cd7004e2807] app/views/books/index.html.erb:23:in `_app_views_books_index_html_erb__879124352395591768_27663240'
db/migrate/create_books
class CreateBooks < ActiveRecord::Migration[5.1]
def change
create_table :books do |t|
t.string :name
t.string :author
t.string :image
t.string :attachment
t.timestamps
end
end
end
schema.rb
ActiveRecord::Schema.define(version: 20170920131113) do
create_table "books", force: :cascade do |t|
t.string "name"
t.string "author"
t.string "image"
t.string "attachment"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
books/index.html.erb
<% if !flash[:notice].blank? %>
<div class="alert alert-info">
<%= flash[:notice] %>
</div>
<%end%>
<br />
<%= link_to "Нова Книга", new_book_path, class: "btn btn-primary mb1 bg-blue" %>
<br />
<br />
<table class="table table-boarded table-striped">
<thread>
<tr>
<th>Име</th>
<th>Aвтор</th>
<th>Корица</th>
<th>Линк за сваляне</th>
<th> </th>
</tr>
</thread>
<tbody>
<% @books.each do |book| %>
<tr>
<td><%= book.name %></td>
<td><%= book.author %></td>
<td><%= image_tag book.image_url.to_s%></td>
<td><%= link_to "Свали Книга", book.attachment_url %></td>
<td><%= button_to "Delete", book, method: :delete, class: "btn btn-danger", confirm: "Сигурни ли сте, че желаете да изтриете #{book.name}?" %></td>
</tr>
<% end %>
</tbody>
</table>
controllers/books_controller.rb
class BooksController < ApplicationController
def index
@books = Book.all
end
def new
@book = Book.new
end
def create
@book = Book.new(book_params)
if @book.save
redirect_to books_path, notice: "Kнигата '#{@book.name}' е качена успешно!"
else
render 'new'
end
end
def destroy
@book = Book.find(params[:id])
@book.destroy
redirect_to books_path, notice: "Книгата е изтрита!"
end
private
def book_params
params.require(:book).permit(:name, :author, :image, :attachment)
end
end
I was able to get it running, this was the answer that helped.
https://stackoverflow.com/a/32159297/7264254
Maybe you added the captcha column after originally running heroku run rake db:migrate the first time with that migration included? If that is the case, you need to reset the database (Please note that this will clear all the data) with
heroku pg:reset DATABASE and then migrate it again with
heroku run rake db:migrate After these the captcha should be available on Heroku too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.