我的配置:
Windows: 10 Education
Rails: 5.2.1
Ruby: 2.4.4p296
Heroku: heroku/7.7.7 win32-x64 node-v10.7.0
postgres: postgres (PostgreSQL) 10.3
> rails new my_app --database=postgresql
> cd my_app
第二步:生成控制器
> rails generate controller static_pages
步骤3:编辑/app/controllers/static\u pages\u controller文件
class StaticPagesController < ApplicationController
def show
end
def destroy
end
end
/应用程序/视图/静态页面/显示.html.erb:
this is the show view
here is a link to the delete action:
<%= link_to t('logout'), logout_path, method: :delete %>
/应用程序/视图/静态页面/销毁.html.erb:
this is the destroy view which is called with a link_to method: :delete
第5步:编辑/config/路由.rb文件
Rails.application.routes.draw do
root 'static_pages#show'
get 'static_pages/show'
delete '/logout', to: 'static_pages#destroy'
end
> rails routes
Prefix Verb URI Pattern Controller#Action
root GET / staticpages#show
staticpages_show GET /staticpages/show(.:format) staticpages#show
logout DELETE /logout(.:format) staticpages#destroy
rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
步骤7:创建数据库并迁移
> rails db:create
Created database 'my_app_development'
Created database 'my_app_test'
> rails db:migrate
第8步:启动服务器
> rails server
步骤9:转到本地主机:3000/然后单击显示的链接。链接工作并向服务器发送删除操作
Started GET "/" for 127.0.0.1 at 2018-09-03 18:43:52 +0200
Processing by StaticPagesController#show as HTML
Rendering static_pages/show.html.erb within layouts/application
Rendered static_pages/show.html.erb within layouts/application (12.2ms)
Completed 200 OK in 504ms (Views: 486.7ms | ActiveRecord: 0.0ms)
Started DELETE "/logout" for 127.0.0.1 at 2018-09-03 18:43:57 +0200
Processing by StaticPagesController#destroy as HTML
Parameters: {"authenticity_token"=>"10NHmV8N4tF3O0r/YYtKtKmHm3xthGjPAE51osb7L9skCM5ZoM2RoiCtZD4Crh9d69ndTOeNRMmIW28ipI/z9A=="}
Rendering static_pages/destroy.html.erb within layouts/application
Rendered static_pages/destroy.html.erb within layouts/application (0.0ms)
Completed 200 OK in 90ms (Views: 73.0ms | ActiveRecord: 0.0ms)
第10步:创建heroku应用程序(您必须在系统上登录heroku)
> heroku create
第11步:把你的工作推给Heroku
> git add -A
> git commit -m "init"
> git push --set-upstream heroku master
第12步:打开你的Heroku应用程序,像第9步一样操作,但是失败了,因为JavaScript似乎不能正常工作
(...) Started GET "/" for 84.147.254.28 at 2018-09-03 16:47:44 +0000
(...) Processing by StaticPagesController#show as HTML
(...) Rendering static_pages/show.html.erb within layouts/application
(...) Rendered static_pages/show.html.erb within layouts/application (9.2ms)
(...) Completed 200 OK in 27ms (Views: 13.7ms)
.
.
.
(...) Started GET "/logout" for 84.147.254.28 at 2018-09-03 16:48:05 +0000
(...) ActionController::RoutingError (No route matches [GET] "/logout"):
这要么是Rails上的一个明显错误,要么是Heroku方面的一个明显错误,因为我所做的只是jsut创建一个新的Rails应用程序并更改了路由,生成了一个控制器并为控制器操作创建了两个视图。
如果您想查看应用程序和部署到heroku的应用程序的所有源代码,请参阅以下链接。
BitBucket Repo
这里的应用程序:
Heroku app
编辑
:通过删除不必要的日志信息和时间戳,使步骤12的输出更加清晰