0

私のアプリはローカルサーバーで問題なく実行できますが、gitからherokuにプッシュすると、herokuでは機能しません。heroku run rake db:migrateを実行しましたが、まだ運がありません。これはusernameメソッドと関係があると思いますが、herokuではなくローカルで機能する理由がわかりません。

2013-03-01T05:45:00+00:00 app[web.1]:
2013-03-01T05:45:00+00:00 app[web.1]:     11:   <% if current_user == pin.user %>
2013-03-01T05:45:00+00:00 app[web.1]:   app/views/pins/index.html.erb:4:in `_app_views_pins_index_html_erb__3245926179851309408_37549160'
2013-03-01T05:45:00+00:00 app[web.1]: cache: [GET /] miss
2013-03-01T05:45:00+00:00 app[web.1]:
2013-03-01T05:45:01+00:00 app[web.1]:
2013-03-01T05:45:01+00:00 app[web.1]: Started GET "/" for 99.190.128.33 at 2013-03-01 05:45:01 +0000
2013-03-01T05:45:01+00:00 app[web.1]:
2013-03-01T05:45:01+00:00 app[web.1]: Processing by PinsController#index as HTML
2013-03-01T05:45:01+00:00 heroku[router]: at=info method=GET path=/ host=railsapp-                     test.herokuapp.com fwd="99.190.128.33" dyno=web.1 queue=0 wait=0ms connect=0ms service=38ms   status=500 bytes
=643
2013-03-01T05:45:01+00:00 app[web.1]:   Rendered static_pages/_home.html.erb (3.7ms)
2013-03-01T05:45:01+00:00 app[web.1]:   Rendered pins/_pin.html.erb (11.3ms)
2013-03-01T05:45:01+00:00 app[web.1]:   Rendered pins/index.html.erb within layouts/application (20.5ms)
2013-03-01T05:45:01+00:00 app[web.1]:     7:            <strong>
2013-03-01T05:45:01+00:00 app[web.1]:     8:                    Posted by <%= pin.user.username  %>
2013-03-01T05:45:01+00:00 app[web.1]:
2013-03-01T05:45:01+00:00 app[web.1]:   app/views/pins/_pin.html.erb:8:in  `_app_views_pins__pin_html_erb___1817132116748238264_25273940'
2013-03-01T05:45:01+00:00 app[web.1]:   app/views/pins/index.html.erb:4:in  `_app_views_pins_index_html_erb__3245926179851309408_37549160'
2013-03-01T05:45:01+00:00 app[web.1]:   app/controllers/pins_controller.rb:8:in `index'
2013-03-01T05:45:01+00:00 app[web.1]: Completed 500 Internal Server Error in 22ms
2013-03-01T05:45:01+00:00 app[web.1]:
2013-03-01T05:45:01+00:00 app[web.1]: ActionView::Template::Error (undefined method `username'  for nil:NilClass):
2013-03-01T05:45:01+00:00 app[web.1]:     5:    </p>
2013-03-01T05:45:01+00:00 app[web.1]:     6:    <p>
2013-03-01T05:45:01+00:00 app[web.1]:     9:            </strong>
2013-03-01T05:45:01+00:00 app[web.1]:     11:   <% if current_user == pin.user %>
2013-03-01T05:45:01+00:00 app[web.1]:     10:   </p>
2013-03-01T05:45:01+00:00 app[web.1]:
2013-03-01T05:45:01+00:00 app[web.1]: cache: [GET /] miss
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 app[web.1]: Started GET "/" for 99.190.128.33 at 2013-03-01 05:45:02  +0000
2013-03-01T05:45:02+00:00 app[web.1]: Processing by PinsController#index as HTML
2013-03-01T05:45:02+00:00 app[web.1]:   Rendered static_pages/_home.html.erb (4.4ms)
2013-03-01T05:45:02+00:00 app[web.1]:   Rendered pins/index.html.erb within layouts/application  (22.2ms)
2013-03-01T05:45:02+00:00 app[web.1]:     6:    <p>
2013-03-01T05:45:02+00:00 app[web.1]: Completed 500 Internal Server Error in 23ms
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 app[web.1]: ActionView::Template::Error (undefined method `username'  for nil:NilClass):
2013-03-01T05:45:02+00:00 app[we
b.1]:   app/views/pins/_pin.html.erb:8:in  `_app_views_pins__pin_html_erb___1817132116748238264_25273940'
2013-03-01T05:45:02+00:00 app[web.1]:   app/controllers/pins_controller.rb:8:in `index'
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 app[web.1]:     11:   <% if current_user == pin.user %>
2013-03-01T05:45:02+00:00 app[web.1]:     8:                    Posted by <%= pin.user.username  %>
2013-03-01T05:45:02+00:00 app[web.1]:   Rendered pins/_pin.html.erb (12.4ms)
2013-03-01T05:45:02+00:00 app[web.1]:     10:   </p>
2013-03-01T05:45:02+00:00 app[web.1]:     5:    </p>
2013-03-01T05:45:02+00:00 app[web.1]:   app/views/pins/index.html.erb:4:in  `_app_views_pins_index_html_erb__3245926179851309408_37549160'
2013-03-01T05:45:02+00:00 app[web.1]:     7:            <strong>
2013-03-01T05:45:02+00:00 app[web.1]: cache: [GET /] miss
2013-03-01T05:45:02+00:00 app[web.1]:     9:            </strong>
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 app[web.1]: Started GET "/" for 99.190.128.33 at 2013-03-01 05:45:02 +0000
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 app[web.1]: Processing by PinsController#index as HTML
2013-03-01T05:45:02+00:00 app[web.1]:   Rendered static_pages/_home.html.erb (1.6ms)
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 heroku[router]: at=info method=GET path=/ host=railsapp- test.herokuapp.com fwd="99.190.128.33" dyno=web.1 queue=0 wait=3ms connect=2ms service=63ms  status=500 bytes
=643
2013-03-01T05:45:02+00:00 app[web.1]:     8:                    Posted by <%= pin.user.username  %>
2013-03-01T05:45:02+00:00 app[web.1]:     5:    </p>
2013-03-01T05:45:02+00:00 app[web.1]:     6:    <p>
2013-03-01T05:45:02+00:00 app[web.1]:   Rendered pins/_pin.html.erb (47.0ms)
2013-03-01T05:45:02+00:00 app[web.1]:     7:            <strong>
2013-03-01T05:45:02+00:00 app[web.1]:   Rendered pins/index.html.erb within layouts/application  (50.3ms)
2013-03-01T05:45:02+00:00 app[web.1]:     11:   <% if current_user == pin.user %>
2013-03-01T05:45:02+00:00 app[web.1]:   app/views/pins/_pin.html.erb:8:in  `_app_views_pins__pin_html_erb___1817132116748238264_25273940'
2013-03-01T05:45:02+00:00 app[web.1]:   app/controllers/pins_controller.rb:8:in `index'
2013-03-01T05:45:02+00:00 app[web.1]:     9:            </strong>
2013-03-01T05:45:02+00:00 app[web.1]:   app/views/pins/index.html.erb:4:in  `_app_views_pins_index_html_erb__3245926179851309408_37549160'
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 app[web.1]: cache: [GET /] miss
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 app[web.1]:     10:   </p>
2013-03-01T05:45:02+00:00 app[web.1]: Completed 500 Internal Server Error in 51ms
2013-03-01T05:45:02+00:00 app[web.1]: ActionView::Template::Error (undefined method `username'  for nil:NilClass):
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 app[web.1]: Started GET "/" for 99.190.128.33 at 2013-03-01 05:45:02    +0000
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 app[web.1]: Processing by PinsController#index as HTML
2013-03-01T05:45:02+00:00 app[web.1]:   Rendered static_pages/_home.html.erb (2.8ms)
2013-03-01T05:45:02+00:00 app[web.1]: Completed 500 Internal Server Error in 14ms
2013-03-01T05:45:02+00:00 app[web.1]:   Rendered pins/index.html.erb within layouts/application  (12.7ms)
2013-03-01T05:45:02+00:00 app[web.1]:   Rendered pins/_pin.html.erb (8.0ms)
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 app[web.1]: ActionView::Template::Error (undefined method `username'  for nil:NilClass):
2013-03-01T05:45:02+00:00 app[web.1]:     5:    </p>
2013-03-01T05:45:02+00:00 app[web.1]:     6:    <p>
2013-03-01T05:45:02+00:00 app[web.1]:     8:                    Posted by <%= pin.user.username %>
2013-03-01T05:45:02+00:00 app[web.1]:     9:            </strong>
2013-03-01T05:45:02+00:00 app[web.1]:   app/views/pins/_pin.html.erb:8:in `_app_views_pins__pin_html_erb___1817132116748238264_25273940'
2013-03-01T05:45:02+00:00 app[web.1]:     11:   <% if current_user == pin.user %>
2013-03-01T05:45:02+00:00 app[web.1]:     10:   </p>
2013-03-01T05:45:02+00:00 app[web.1]:     7:            <strong>
2013-03-01T05:45:02+00:00 heroku[router]: at=info method=GET path=/ host=railsapp- test.herokuapp.com fwd="99.190.128.33" dyno=web.1 queue=0 wait=0ms connect=3ms service=22ms  status=500 bytes
=643
2013-03-01T05:45:02+00:00 app[web.1]:   app/views/pins/index.html.erb:4:in   `_app_views_pins_index_html_erb__3245926179851309408_37549160'
2013-03-01T05:45:02+00:00 app[web.1]:   app/controllers/pins_controller.rb:8:in `index'
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 app[web.1]:
2013-03-01T05:45:02+00:00 app[web.1]: cache: [GET /] miss
2013-03-01T05:45:02+00:00 heroku[router]: at=info method=GET path=/ host=railsapp-test.herokuapp.com fwd="99.190.128.33" dyno=web.1 queue=0 wait=0ms connect=1ms service=32ms status=500 bytes
=643

編集:pins_controller.rbの下のコードは次のとおりです。

def create
    @pin = current_user.pins.new(params[:pin])

    respond_to do |format|
      if @pin.save
        format.html { redirect_to pins_path, notice: 'Pin was successfully created.' }
        format.json { render json: @pin, status: :created, location: @pin }
      else
        format.html { render action: "new" }
        format.json { render json: @pin.errors, status: :unprocessable_entity }
      end
    end
  end
4

1 に答える 1

0

ユーザー名の方法は問題ありません。問題は、pinインスタンスにユーザーがいないことが原因です(つまり、pin.userはnilです)。ピンを保存するときは、ユーザーが正しく割り当てられていることを確認してください。

于 2013-03-01T06:28:36.190 に答える