ruby-on-rails – 用户路由 – Rails
发布时间:2020-12-17 02:03:35 所属栏目:百科 来源:网络整理
导读:我在rails应用程序中设置用户路由时遇到问题. 在routes.rb中,我添加了资源:users. TestApp::Application.routes.draw do resources :users root :to = 'xxx#home' match '/about',to: 'xxx#about' match '/test',to: 'xxx#test' match '/news',to: 'xxx#new
我在rails应用程序中设置用户路由时遇到问题.
在routes.rb中,我添加了资源:users. TestApp::Application.routes.draw do resources :users root :to => 'xxx#home' match '/about',to: 'xxx#about' match '/test',to: 'xxx#test' match '/news',to: 'xxx#news' match '/signup',to: 'users#new' end 在users_controller.rb中,我添加了: class UsersController < ApplicationController def new end def show @user = User.find(params[:id]) end end 我用线创建了新的show.html.rb文件: <%= @user.name %>,<%= @user.email %> 但是当我部署到heroku时,我得到了这个信息,我看不到那个页面. heroku[router]: at=info method=GET path=/users/1 有没有解决方案,或者我做错了什么? 解决方法
你确定heroku上存在id = 1的用户吗?如果是的话,你使用过吗?
$heroku run console 此命令在生产环境中调出rails控制台.在其中,你做过那样的事吗? u = User.create(somehash_with_attrs) # .. or u = User.new # ... u.save u.id # => 1 or 23 # If your are not sure which id your user has try the following User.first.id 并且您知道yourapp.domain / users / 1指向id = 1的用户记录而不是数据库中的第一条记录. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |