【发布时间】:2013-02-21 21:47:16
【问题描述】:
我正在从事一个有用户且用户有个人资料的项目。我正在使用设计 gem 进行用户身份验证。我更改了控制器中某个操作的路径,这导致了无法解释的行为。
Test::Application.routes.draw do
match '/:username' => 'profile#show' , :as => :username
get "profile/update"
get "static_pages/index"
devise_for :users
服务器日志显示如下。
Started POST "/users" for 127.0.0.1 at 2013-02-22 03:07:48 +0530
Processing by ProfileController#show as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Tr90BvI6sztk7gxlPm6KF3td3xIe91SpCZDGsIniv60=", "user"=>{"username"=>"example", "email"=>"example@email.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up", "username"=>"users"}
Rendered profile/show.html.erb within layouts/application (0.1ms)
Completed 200 OK in 12ms (Views: 11.5ms | ActiveRecord: 0.0ms)
数据没有被插入数据库并且用户名参数正在改变,当我将路由更改为默认路由时,即
match '/:username' => 'profile#show' , :as => :username
改为
get "profile/show"
一切恢复正常。正在插入数据,一切正常。我不明白为什么在用户注册时调用配置文件控制器的操作。rake routes 给出以下输出
username /:username(.:format) profile#show
profile_update GET /profile/update(.:format) profile#update
static_pages_index GET /static_pages/index(.:format) static_pages#index
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
root / static_pages#inde
提前致谢。
【问题讨论】:
标签: ruby-on-rails ruby routing controllers