这适用于本地,但不适用于heroku。
我尝试过本地迁移,然后推送到heroku它没有用。 我试过heroku运行rake db:migrate,然后重新启动它不起作用。
我试图重新启动dyno,它也没有用。
有什么我可以检查哪些会提供更多细节?我正在查看heroku运行rake db:migrate:status,但它只显示一般迁移创建书籍。
错误:
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'
分贝/迁移/ 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
书籍/ 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>
控制器/ 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
答案 0 :(得分:0)
我能够让它运行,这是有帮助的答案。
https://stackoverflow.com/a/32159297/7264254
也许您在最初运行heroku运行后添加了captcha列 rake db:第一次迁移包含该迁移?如果说 是这样的,你需要重置数据库(请注意这一点 将用
清除所有数据heroku pg:重置DATABASE,然后使用
再次迁移它heroku run rake db:migrate之后,验证码应该可用 也是在Heroku上。