简体   繁体   English

Rails heroku ActionView::Template::Error(未定义的方法`author'

[英]Rails heroku ActionView::Template::Error (undefined method `author'

This works locally, but not in heroku.这在本地有效,但在 heroku 中无效。

I have tried migrating locally, then pushing to heroku it did not work.我试过在本地迁移,然后推送到 heroku 它没有用。 I have tried heroku run rake db:migrate, then restarting it did not work.我试过 heroku run rake db:migrate,然后重新启动它没有用。

I have tried to restart the dyno, it also did not work.我试图重新启动 dyno,它也没有工作。

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.我正在查看 heroku run rake db:migrate:status,但它只显示一般迁移创建书籍。

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 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书籍/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>&nbsp;</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控制器/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 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?也许您在最初运行 heroku run rake db:migrate 之后添加了验证码列,其中包括该迁移? 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 pg:reset DATABASE 然后再次迁移它

heroku run rake db:migrate After these the captcha should be available on Heroku too. heroku run rake db:migrate 在这些之后,验证码也应该在 Heroku 上可用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 heroku ActionView :: Template :: Error(未定义的方法“电子邮件” - heroku ActionView::Template::Error (undefined method `email' Rails:ActionView :: Template :: Error - 未定义的方法&#39;comment&#39; - Rails: ActionView::Template::Error - undefined method 'comment' Rails + Heroku:ActionView :: Template :: Error - Rails + Heroku : ActionView::Template::Error ActionView中的Heroku未定义方法错误 - Heroku undefined method error in ActionView Heroku ActionView :: Template :: Error(nil:NilClass的未定义方法“名称”) - Heroku ActionView::Template::Error (undefined method `name' for nil:NilClass) 在Heroku上的ActionView :: Template :: Error(nil:NilClass的未定义方法“ program”) - ActionView::Template::Error (undefined method `program' for nil:NilClass) on heroku Heroku 问题,ActionView::Template::Error(nil:NilClass 的未定义方法“名称”): - Heroku issue, ActionView::Template::Error (undefined method `name' for nil:NilClass): ActionView :: Template :: Error(未定义方法…)在本地工作,但不适用于Heroku - ActionView::Template::Error (undefined method…) Works locally, but not on Heroku Rails jbuilder 错误:ActionView::Template::Error(未定义的方法 - Rails jbuilder error: ActionView::Template::Error (undefined method Rails Minitest ActionView :: Template :: Error:nil:NilClas的未定义方法 - Rails Minitest ActionView::Template::Error: undefined method for nil:NilClas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM