简体   繁体   English

Heroku生产环境中不存在Ruby on Rails应用程序页面

[英]Ruby on Rails Application Page Does Not Exist in Heroku Production Environment

In my app during testing on localhost I am able to click on a link that brings me to the edit_event_path(event) page and it works perfectly. localhost上进行测试时,在我的应用程序中,我可以单击一个链接,将我带到edit_event_path(event)页面,它可以正常运行。

When I pushed it to Heroku I keep getting the error "This page does not exist" however I am still able to access the /event index page. 当我将其推送到Heroku时,我不断收到错误消息“此页面不存在”,但是我仍然能够访问/event索引页面。

It only appears to be for the edit page. 它似乎仅用于编辑页面。

My routes.rb 我的routes.rb

Rails.application.routes.draw do
  resources :approvals
  devise_for :users
  resources :events

  resources :roles
  # The priority is based upon order of creation: first created -> highest priority.
  # See how all your routes lay out with "rake routes".

  scope "/admin" do
    resources :users do
      collection do
        match 'update_collection', via: [:put, :patch]
      end
    end
  end
  # You can have the root of your site routed with "root"
  root 'events#index'

  # Example of regular route:
  #   get 'products/:id' => 'catalog#view'

  # Example of named route that can be invoked with purchase_url(id: product.id)
  #   get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

  # Example resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Example resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Example resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Example resource route with more complex sub-resources:
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', on: :collection
  #     end
  #   end

  # Example resource route with concerns:
  #   concern :toggleable do
  #     post 'toggle'
  #   end
  #   resources :posts, concerns: :toggleable
  #   resources :photos, concerns: :toggleable

  # Example resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end
end

Heroku Logs Heroku原木

 2016-02-07T18:10:42.416537+00:00 app[web.1]: [2016-02-07 18:10:42] INFO  WEBrick 1.3.1
    2016-02-07T18:10:42.417158+00:00 app[web.1]: [2016-02-07 18:10:42] INFO  WEBrick::HTTPServer#start: pid=3 port=33086
    2016-02-07T18:10:42.416617+00:00 app[web.1]: [2016-02-07 18:10:42] INFO  ruby 2.2.4 (2015-12-16) [x86_64-linux]
    2016-02-07T18:10:42.689042+00:00 heroku[web.1]: State changed from starting to up
    2016-02-07T18:10:44.112872+00:00 heroku[router]: at=info method=GET path="/" host=rocky-garden-45285.herokuapp.com request_id=68c4f973-c80d-4c5a-8fcb-b0278f2cbf91 fwd="31.54.189.126" dyno=web.1 connect=1ms service=270ms status=200 bytes=3966
    2016-02-07T18:10:44.310780+00:00 heroku[router]: at=info method=GET path="/assets/application-f963057a4622f6dd81c09aa4b5984113c498b7784f67dfc6ef8bff81e17352df.css" host=rocky-garden-45285.herokuapp.com request_id=9fae1fe7-dceb-451a-836f-e52cda494151 fwd="31.54.189.126" dyno=web.1 connect=0ms service=23ms status=304 bytes=133
    2016-02-07T18:10:44.535082+00:00 heroku[router]: at=info method=GET path="/assets/application-6abdf7298b102105c44b987e39846d7496e6a9c5e36a3eac9c8e68189eaa9865.js" host=rocky-garden-45285.herokuapp.com request_id=759a6a46-fe88-4db6-8c09-d79a1a9d005d fwd="31.54.189.126" dyno=web.1 connect=0ms service=22ms status=304 bytes=133
    2016-02-07T18:10:45.045464+00:00 heroku[router]: at=info method=GET path="/assets/submit.png" host=rocky-garden-45285.herokuapp.com request_id=32c0080b-4eea-493a-a49a-73a517d5339d fwd="31.54.189.126" dyno=web.1 connect=0ms service=90ms status=304 bytes=343
    2016-02-07T18:10:45.061932+00:00 heroku[router]: at=info method=GET path="/assets/pencil.png" host=rocky-garden-45285.herokuapp.com request_id=b05f2f39-6f94-44a7-89e7-1a4cd20d2afb fwd="31.54.189.126" dyno=web.1 connect=1ms service=302ms status=304 bytes=343
    2016-02-07T18:10:45.042709+00:00 heroku[router]: at=info method=GET path="/assets/doc.png" host=rocky-garden-45285.herokuapp.com request_id=efaa4827-c548-485f-8d82-e98313823573 fwd="31.54.189.126" dyno=web.1 connect=0ms service=303ms status=304 bytes=343
    2016-02-07T18:10:48.512052+00:00 heroku[router]: at=info method=GET path="/events/1/edit" host=rocky-garden-45285.herokuapp.com request_id=72bfc70a-ef5b-401b-9b62-cf7f1f2f14c1 fwd="31.54.189.126" dyno=web.1 connect=0ms service=22ms status=404 bytes=1829
    2016-02-07T18:10:48.644811+00:00 heroku[router]: at=info method=GET path="/events/1/edit" host=rocky-garden-45285.herokuapp.com request_id=64f69780-d399-4f81-9354-b7998b98afb2 fwd="31.54.189.126" dyno=web.1 connect=1ms service=12ms status=404 bytes=1829
    2016-02-07T18:10:52.675030+00:00 heroku[router]: at=info method=GET path="/events/1/edit" host=rocky-garden-45285.herokuapp.com request_id=50101311-033a-4dda-a4fb-c750144f8685 fwd="31.54.189.126" dyno=web.1 connect=1ms service=13ms status=404 bytes=1829
    2016-02-07T18:10:52.805759+00:00 heroku[router]: at=info method=GET path="/events/1/edit" host=rocky-garden-45285.herokuapp.com request_id=0b665b71-6949-47da-9061-78d7a9014b3a fwd="31.54.189.126" dyno=web.1 connect=0ms service=11ms status=404 bytes=1829

EventsController EventsController

class EventsController < ApplicationController
  before_filter :authenticate_user!
  before_action :set_event, only: [:show, :edit, :update, :destroy]
  before_action :set_users
  before_action :set_user, except: [:index]

  # GET /events
  # GET /events.json
  def index
    @events = Event.where(:approved => true)
    @users = User.all.order("created_at DESC")
  end

  # GET /events/1
  # GET /events/1.json
  def show
  end

  # GET /events/new
  def new
    @event = Event.new
  end

  # GET /events/1/edit
  def edit
  end

  # POST /events
  # POST /events.json
  def create
    @event = Event.new(event_params)

    respond_to do |format|
      if @event.save
        format.html { redirect_to @event, notice: 'Event was successfully created.' }
        format.json { render :show, status: :created, location: @event }
      else
        format.html { render :new }
        format.json { render json: @event.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /events/1
  # PATCH/PUT /events/1.json
  def update
    respond_to do |format|
      if @event.update(event_params)
        format.html { redirect_to @event, notice: 'Event was successfully updated.' }
        format.json { render :show, status: :ok, location: @event }
      else
        format.html { render :edit }
        format.json { render json: @event.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /events/1
  # DELETE /events/1.json
  def destroy
    @event.destroy
    respond_to do |format|
      format.html { redirect_to events_url, notice: 'Event was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_event
      @event = Event.find(params[:id])
    end

    def set_user
      @user = User.find(params[:id])
    end

    def set_users
      @users = User.all.order("created_at DESC")
    end

    # Never trust parameters from the scary internet, only allow the white list through.

    def event_params
      params.require(:event).permit(:name, :user_id)
    end
end

I am not sure if any other logs or such are required to answer my question but if you comment I will provide them! 我不确定是否需要其他日志或其他日志来回答我的问题,但是如果您发表评论,我会提供它们! Thank you! 谢谢!

Your code looks fine - it's likely there's no Event with ID 1. Either you haven't created any in production yet, or you already deleted it. 您的代码看起来不错-可能没有ID为1的Event 。您可能尚未在生产中创建任何Event ,或者您已经删除了它。 /events/1 will probably 404 as well. /events/1也可能会是404。

Go to /events/new to create an Event . 转到/events/new创建一个Event You can also log into your Heroku database with heroku pg:psql (assuming you have the toolbelt installed) and SELECT id FROM events to verify which IDs are present. 您也可以登录到您的Heroku数据库heroku pg:psql (假设你有工具区安装)和SELECT id FROM events ,以验证其ID是否存在。

You're also loading @user using params[:id] , which is the Event 's ID. 您还使用params[:id]加载@user ,这是Event的ID。 If a User doesn't exist with the same ID as the Event , Rails raises the same RecordNotFound exception, which is what comes back to you as a 404. It looks like you've got login on this application, so you probably want to be loading that from session[:user_id] , via Devise, or however else you built authentication. 如果不存在与Event具有相同ID的User ,Rails会引发相同的RecordNotFound异常,这是作为404返回的。看起来您已经在该应用程序上登录了,所以您可能想要通过Devise从session[:user_id]加载,否则您将建立身份验证。

暂无
暂无

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

相关问题 Rails / Heroku中的生产环境如何工作? - How does the production environment in Rails / Heroku work? 无法在Heroku上运行的Ruby on Rails 4.1.4应用程序中为生产环境设置secret_key_base - Unable to set secret_key_base for the production environment in Ruby on Rails 4.1.4 application running on Heroku ruby on rails:heroku:“生产”环境缺少“secret_key_base” - ruby on rails: heroku: Missing `secret_key_base` for 'production' environment Ruby on Rails应用程序在生产环境中找不到样式表和JavaScript? - Ruby on Rails application can not find stylesheets and javascript in production environment? 在红宝石中,为什么某些控制器在生产环境中不起作用? - In ruby on rails, why some controller does not work in the production environment? Ruby on Rails / Heroku-您要查找的页面不存在 - Ruby on Rails / Heroku - The page you were looking for doesn't exist Heroku Ruby On Rails 服务器日志显示“用户”不存在 - Heroku Ruby On Rails Server Logs says 'Users' does not Exist 如何调整在使用生产级别Heroku Postgres的Heroku上运行的Ruby on Rails应用程序? - How to tune a Ruby on Rails application running on Heroku which uses production level Heroku Postgres? 在Heroku上未设置Rails环境变量 - Rails Environment Variable Not Getting Set on Production on Heroku Rails 4-.js文件不在生产环境中运行-Heroku - Rails 4 - .js files not running in production environment - Heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM