Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-3.1controllers

Creating a new session or user from a different view/controller


I am creating a Rails App (I'd like to know how to do this in Rails 3.1 and 3.0) on Mac OSX 10.6.

I am using a PagesController to handle mostly static pages but would like to include a signup form on the home page and a login option in a persistent, static top bar on each page generated from my PagesController (home, about, contact, help, etc.).

I am having a little bit of trouble getting forms to work when they are outside of a given controller -> view. For example, I have a SessionsController and then the view (new.html.erb) where I have a form that when submitted creates a new session for login purposes. However, I am looking to implement this same form/functionality outside of the SessionsController and on views belonging to the PagesController (ie home.html.erb or about.html.erb). I'd like to do the same with the signup functionality: I'd like to have a signup form at home.html.erb and not have to send people to the "new" page in the UsersController. It seems like a simple redirect action when the form is submitted but I am having trouble figuring this out. Could someone point me in the right direction?

Thank you!


Solution

  • One option would be have the signup form (.erb) file as a partial and include it in both Users and Pages controllers.

    By that way your registration form is portable to any controller. And when the form is posted after saving you could redirect the user to where the request came from.