0

It is strange. I'm writing custom user registration and want to make redirection to OTHER page after user creation, but it want to call show action.

Here is my controller:

def create
  @user = User.new(params[:user])

respond_to do |format|
  if @user.save
    format.html { redirect_to users_verify_path }
  else
    format.html { render action: "new" }

  end
end

end def verify ... end in routes.rb:

       resources :users

       root :to => 'users#new'

        get "users/verify"

when I rename action into SHOW everything is working. If I name it VERIFY - it shows me:

    Unknown action

    The action 'show' could not be found for UsersController

it is obvious error, because I deleted action show. But WHY it is redirecting to show ?

MID
  • 1,815
  • 4
  • 29
  • 40

1 Answers1

1

Try to write get "users/verify" before resources :users

or

resources :users do
  member do
    get 'verify'
  end
end
Nicklasos
  • 566
  • 3
  • 8
  • Yeah, it is working. Thanks. Can you explain why it is working like that ? – MID Aug 30 '12 at 11:08
  • Rails routes are matched in the order they are specified, so if you have a resources :users above a get 'users/verify' the show action’s route for the resources line will be matched before the get line. It`s from rails docs. – Nicklasos Aug 30 '12 at 11:13
  • Can you suggest reason of my next error ? When I try to use `def verify @user = User.find(params[:id])` shows me error - `Couldn't find User without an ID` – MID Aug 30 '12 at 11:14
  • I need to use user data to in this action. – MID Aug 30 '12 at 11:15
  • Try to use member inside resources users, as i wrote it in my answer above, then id shoul be in url and params[:id] – Nicklasos Aug 30 '12 at 11:23
  • Can you look here also http://stackoverflow.com/questions/12195775/how-use-data-related-to-object-which-im-not-saving-to-database ? – MID Aug 30 '12 at 11:25