Ruby on Rails: Custom actions

后端 未结 1 1842
小鲜肉
小鲜肉 2021-01-22 19:41

I\'m new to rails, so I\'ll just explain my situation to you:

I\'ve got a User Model and a UsersController. Users log in with their email address and a password. Special

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-22 20:17

    You probably have something like this in your routes file. (If not, please post that.)

    resources :users 
    

    If you want to add a custom action that acts on a single User, you can add that as a :member like this.

    resources :users do
      member do
        get :activate
      end
    end
    

    Note that using a get for something that modifies data is a bit wrong, but you're talking about hitting this from a link in an email.

    As you play with routes don't forget that rake routes will show you all of the routes that you currently have available to you.

    0 讨论(0)
提交回复
热议问题