• #8 楼 @nowherekai 谢谢前辈,这下我对网络路由这块懂了。至于说 accounts,loved 那几个更新,我就超链接多个页面好了。

  • #6 楼 @nowherekai

    Rails.application.routes.draw do
      # get 'password_resets/new'
    
      # get 'password_resets/edit'
    
      # get 'sessions/new'
    
      # get 'users/new'
    
      root               'static_pages#home'
      get 'help'       =>'static_pages#help'
      get 'about'      =>'static_pages#about' 
      get 'contact'    =>'static_pages#contact'
      get 'signup'     =>'users#new'
      get 'login'      =>'sessions#new'
      post 'login'     =>'sessions#create'
      delete 'logout'  =>'sessions#destroy'
    
      # 用户
      resources :users do 
        member do
          get :following, :followers, :settings
        end
      end
    
    
      resources :account_activations, only: [:edit] # 账号激活
      resources :password_resets, only: [:new, :create, :edit, :update]
      resources :microposts, only:[:create, :destroy]
      resources :relationships, only:[:create, :destroy]
    end
    

    大神请指教

  • #4 楼 @nowherekai 路由代码:

                     Prefix Verb   URI Pattern                             Controller#Action
                       root GET    /                                       static_pages#home
                       help GET    /help(.:format)                         static_pages#help
                      about GET    /about(.:format)                        static_pages#about
                    contact GET    /contact(.:format)                      static_pages#contact
                     signup GET    /signup(.:format)                       users#new
                      login GET    /login(.:format)                        sessions#new
                            POST   /login(.:format)                        sessions#create
                     logout DELETE /logout(.:format)                       sessions#destroy
             following_user GET    /users/:id/following(.:format)          users#following
             followers_user GET    /users/:id/followers(.:format)          users#followers
              settings_user GET    /users/:id/settings(.:format)           users#settings
                       user GET    /users/:id(.:format)                    users#update
                      users GET    /users(.:format)                        users#index
                            POST   /users(.:format)                        users#create
                   new_user GET    /users/new(.:format)                    users#new
                  edit_user GET    /users/:id/edit(.:format)               users#edit
                            GET    /users/:id(.:format)                    users#show
                            PATCH  /users/:id(.:format)                    users#update
                            PUT    /users/:id(.:format)                    users#update
                            DELETE /users/:id(.:format)                    users#destroy
    edit_account_activation GET    /account_activations/:id/edit(.:format) account_activations#edit
            password_resets POST   /password_resets(.:format)              password_resets#create
         new_password_reset GET    /password_resets/new(.:format)          password_resets#new
        edit_password_reset GET    /password_resets/:id/edit(.:format)     password_resets#edit
             password_reset PATCH  /password_resets/:id(.:format)          password_resets#update
                            PUT    /password_resets/:id(.:format)          password_resets#update
                 microposts POST   /microposts(.:format)                   microposts#create
                  micropost DELETE /microposts/:id(.:format)               microposts#destroy
              relationships POST   /relationships(.:format)                relationships#create
               relationship DELETE /relationships/:id(.:format)            relationships#destroy
    
    

    日志文件:

    Started GET "/users/1/settings" for 127.0.0.1 at 2016-01-07 20:19:19 +0800
    Processing by UsersController#settings as HTML
      Parameters: {"id"=>"1"}
      User Load (0.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 1]]
    Completed 400 Bad Request in 1ms
    
    ActionController::ParameterMissing (param is missing or the value is empty: user):
      app/controllers/users_controller.rb:102:in `basic_params'
      app/controllers/users_controller.rb:41:in `settings'
    
    
      Rendered /home/deu/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates/rescues/_source.erb (10.8ms)
      Rendered /home/deu/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates/rescues/_trace.html.erb (3.6ms)
      Rendered /home/deu/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates/rescues/_request_and_response.html.erb (1.0ms)
      Rendered /home/deu/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates/rescues/_web_console.html.erb (1.0ms)
      Rendered /home/deu/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0.beta3/lib/action_dispatch/templates/rescues/diagnostics.html.erb within rescues/layout (30.4ms)
    
    
    
  • dota / lol 高手。。。。

  • #2 楼 @hging stack overflow 那个解释是这样的:

    passreset_user_path(@user)doesn't "pass in" user to the method in question, it generates a URL. The URL will include an ID segment. It will look something like this:

    /users/123/passreset
    

    Your action will be invoked with the ID segment available in params[:id]. It's up to you to find the corresponding user in the database.

    Instead of relying on params[:user], you need to do something along the lines of

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

    The larger issue is that your passreset action makes no sense. It appears to be setup to receive a POST request containing new attributes for the user, but you're linking to it with a button that will produce a GET request with no payload of user attributes.

    You're missing an entire intermediate step, where you show the user a password reset form. Your first request needs to serve that form up, and then that form can POST back to your passreset method.

  • @huacnlee @rei 求指教

  • 过几天才会修改成功,我的就是这样的

  • 来晚了。。。

  • #2 楼 @easonlovewan 你们这种回答对提问者没有多大帮助只有打击,虽然提问需要艺术,但是社区里面每一个人都应该是积极的参与,要么就不要参与进来。

  • #4 楼 @rei 您是论坛第一个 user,我想问您一下为什么我无法修改头像,上传以后总是修改不成功。

  • 在 models 里面定义方法,在 controller 里面的 action 方法调用 model 里面的方法吧,MVC 各部分分工明确。我也是新手,希望相互学习。

  • #13 楼 @easonlovewan 好的 我会慢慢体会的

  • #10 楼 @dongli1985 你的解答总能点到点子上!对了,你是大气所的老师吗?我是国科大的学生~

  • #6 楼 @rei 谢谢你,朋友,我 fork 了看看

  • #5 楼 @kikyous

    more_info GET    /more_info(.:format)      user#edit
        users GET    /users(.:format)          users#index
              POST   /users(.:format)          users#create
     new_user GET    /users/new(.:format)      users#new
    edit_user GET    /users/:id/edit(.:format) users#edit
         user GET    /users/:id(.:format)      users#show
              PATCH  /users/:id(.:format)      users#update
              PUT    /users/:id(.:format)      users#update
              DELETE /users/:id(.:format)      users#destroy
    
    

    more_info 是我自己定义的 route,想在此页面修改用户资料,但是无法用 link_to 链接过去,不知道哪里有问题?

  • #3 楼 @kikyous 我看了,但是对域名和动作的对应还是很困惑

  • #1 楼 @dongli1985 谢谢你回答,可是我要像 github 那样在 github.com/settings/下面的不同网页里修改不同类别的用户信息怎么办?而且 github 也是 rails 写的。

  • 我是这个讨论发起者,是一个初学者,我很意外收到 30 条回复,大家在里面相互艾特,非常活跃。可是我却没有参与其中,可能是因为提问题时候实践少很多东西还不懂,但是作为社区中一员,理应积极互动,而不是提出问题之后就再不理睬,惭愧。