Ruby on Rails Wednesday, June 29, 2011

All -

Don't you love it when someone prefaces their discussion with being
new to Rails?

I have a common user type for my application, and recently added a
second model for a different type of user - different rights,
different tools, etc. I'd like to keep the two models separate - and
wasn't convinced that STI was right for my situation. Therefore...

I'd like to keep the user types separate, but was hoping to share the
sessions controller. Is there a way to modify the session controller
below to allow for two types of users to access it. I started by
making a completely separate sessions controller for the other user
type (let's say user2) - but it certainly doesn't seem DRY.

Should I try to edit the controller below? Use STI or Polymorphic?
Other? Help.


class SessionsController < ApplicationController

def new
@title = "Sign in"
end

def create
user = User.authenticate(params[:session][:email],
params[:session][:password])
if user.nil?
flash.now[:error] = "Invalid email/password combination."
@title = "Sign in"
render 'new'
else
sign_in user
redirect_back_or user
end
end

def destroy
sign_out
redirect_to root_path
end
end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment