Update devise user from multiple forms - ruby-on-rails

I'm working on a site where the sign-up process is multi-step.. so many little forms all update the user model (i'm using the devise gem for user authentication).
Should I post each of these steps to the same update action (overriding the RegistrationController update action)? Each form may require some logic before the update occurs, therefore the forms will require some way of figuring out what form it's currently processing (either a hidden field or trying to establish from what params exist)
..or should I be posting the forms to individual actions (which isn't very RESTful)?
Thanks!

I would not override the RegistrationsController to add an update action. I would have a completely separate UsersController that defines an update action that takes the parameters for updating a user.
Inside Spree (the thing I work on) we've got an update action on CheckoutController that works similar to how you want your users update action to work. Check it out.

Related

Devise: is it possible to de-couple registerable and the user edit profile functionality?

I want to disable user sign up, but still provide edit profile functionality for existing users. Is this possible?
Currently, removing :registerable from th options list also disables the edit profile functionality and edit_user_registration_path is no longer defined.
Any way around this? It is strange that seemingly unrelated functionality is coupled this way.
What I would do would be to create a registration controller and use devise mappings to use that new registration controller. Then for the new and create actions set a flash message and redirect to the root of the app (or your chosen location). If you want to lock it down even more, just override the create method on your user model and throw an exception.
See this answer- disabling Devise registration for production environment only

Using devise helpers in model

Is there any way to use devise's controller helpers in model namely user_signed_in? I have tried adding the following line to my user model, but that doesn't seem to work:
include Devise::Controllers::Helpers
More specifically, I want users to be allowed to be created without password, for which I am implementing the method 'password_required?'. In that method I want to check (before creating the user) if another user is creating that user, or weather he/she is signing up. Any help would be much appreciated.
You cant access controller helper within the model. however you can build an association between users that would allow you to create users on behalf of one another
take a look at rbates screencast on how to implement it
http://railscasts.com/episodes/163-self-referential-association

User CRUD in web application that handles registration and login with Devise

I am currently working on application that is build on rails 3.0.9. All of a sudden the client decided that there should be a place to create a user and edit a user in the admin section of the website.
Now here is the case. The authentication and registration in the web application is handled by devise. If I try to implement a custom USER create method in my controller how should I hash the password in the very same way devise is doing so that I can store that in the database. This also applies to editing the already registered users as well.
I have tried to find the solution but no use. Any help in resolving this would be appreciated.
That's easy. You can setup another controller and form but set it up on your User model. Your form will need to include :email, :password, and :password_confirmation. When you do #user.save in your controller's create action, this will have devise take care of all the hashing requirements under the hood.
If you want to check that your save works (just for testing), add a bang at the end like #user.save! - this is only for testing. Either drop into rails console and you can see the newly added records or tail your log file.
Editing should work along the same lines and you can do #user.update_attribute() in your edit action, or #user.update_attributes() if you prefer mass assignment (this will be subject to any attr_accessible restrictions in your model)

Sign up — Two models, One form

I'm working with Rails 3.1, Devise and Mongoid. Right now I have 3 models — User, Client < User and Developer < User. Is there a way to sign up as either client or a developer from one form using say radio for checking desired account type?
It seems like I can edit only devise's views but not make some changes to controller. Or now?
In Ruby (then in Rails), you can redefine whatever you want, whenever you need.
So indeed, you can redefine the controller if you want to and override one or several actions.
Just create the controller file at the same level it's in the gem itself, or make good use of class_eval.
Using Devise, make sure you add your additional attributes in the attr_accessible list.

Devise, how to create a edit profile page

I have a Rails 3 App using devise. I want to create a User/Profile edit page. Where a user can edit the name, add/change their photo etc...
I'd like to do this in the right rails/devise way. What's the way of handling this? I see a app/views/devise/registrations/edit.html.erb file
Do I edit that file?
Or do I create a app/views/users/edit.html.erb and customize that experience? But then what do you do regarding the controller? Create a new controller?
Thanks
You may edit the devise/registrations/edit.html.{erb,haml} file and customize it to your needs, maybe even add any additional fields that may be in your user model but not on the form.
I believe it's also possible to have a common CRUD interface for users along with the Devise's, but then you'd have to create a new controller and add the views and everything, so it is easier and preferable to simply override Devise's views to change or add what you need.
You can generate them with rails g devise:views.
You could also create a user profile edit page directly from a controller of your choice in the app that modifies your user model appropriately.

Resources