I'm currently working on a Rails project and have decided to use Devise for user registration. The site is using MongoDB (mongoid gem), and I am planning to create a simple sign-up/sign-in system.
So, there is a link in the home page that allows the user to click on it or open in another tab. If he decides to click it, there should be a popup modal that contains the fields and sign-up button, etc. If he opens a new tab, he should see a dedicated page for the sign up process.
So, here is what I have so far. I have installed devise and am able to sign up properly. However, I also want to create the modal effect, in which I used jQuery UI dialog attached to the sign-up link. Then I loaded the sign-up page (/user/sign-up) using dialog.load("path") and stripped the layout when it is an ajax request.
I know this is not the best method to use, so I've been reluctant. Is there a better way of doing this? Preferably a standard method. Any help would be appreciated, or just point me to the right direction. Tutorials will be very nice and helpful. Thanks a lot in advance!
I am not sure if I understand the question, but try this. Run
rails generate devise:views
To create the devise views.
In the views/devise/registration folder you will find the registration page. You should now have access to both the form code and the path user_session mapping to /users/sign_in.
You now have the form and the path, so you should be able to play with the AJAXifying it.
Related
I'm creating a ruby on rails project (soon to be a mobile app). I wanted to utilize the Devise gem for authentication, but I am struggling with the customization of Devise. I wanted to implement a multi-page registration/sign up process. The standard devise gem automatically provides a form that includes email and password. For my project, I wanted the users to add in their name on one page, then their email on the next page, and then their password on the page after, etc. Please see the attached jpg picture for a super basic example.
So far, I separated the registration controller from the devise package. The registration controller comes with the new.html.erb and the edit.html.erb files. I want to take the standard form in the new.html.erb file and split that into multiple html.erb files. The controller would obviously need to be connected to these multiple files. As I was working on it, I realized how complicated it is. I'm wondering is it better to create my own authentication process instead of devise, or is it better to stick with devise?
I really want to make it work with devise, so if you have any suggestions on how to customize the gem to implement the multipage registration that I want, please let me know.
This can be done by modifying the views and the devise controller to accept multi-part registration, but it is cumbersome: I would counsel you to avoid it. Rather, another option would be to: (i) use devise to handle the email and username in one form and then (ii) handle the multi-part registration using the wicked gem - whose sole purpose for existence is to handle multi part registration problems.
In my application a user is taken straight to log-in before they can enter the main site.
I am rendering a navbar partial across the site but I don't want the navbar rendered on the log-in page. I don't want to have to copy and paste the navbar code in to all the views in order to prevent this.
It would be cleaner if there was a way I could stop the navbar showing on the login screen without having to remove the partial.
How do you restrict a partial view from one page in your application?
I am using Devise.
I don't think code is needed in this post but happy to provide if helps. Thanks.
If you are using Devise and you are in a login page, then there is no logged user. Then you may use one of the Devise helpers to achieve what you want. Something like:
if (not user_signed_in?) then
render 'your_partial_with_the_navbar'
end
The only point here is the fact the partial wouldn't render in any page where there is no user logged.
You could also create a better helper yourself, combining the user_signed_in? from Devise with other conditions of yours.
I have this homework from a security class where I need to make an app using some sort of authentification system. So I decided to use ruby on rails and I got it all working with devise at the moment.
But for this home work I need an admin to be able to go into an admin page within the app and be able to modify some security options like :
Being able to lock people after too many login attempts
Complexity of user password
I can't seem to find anything on the internet for this...
Is this possible ? Should I use another method ?
Thank you,
Guillaume
I am a new to the whole rails environment and learning to implement 'devise' gem for my project. Currently I have a tabbed signup/signin form.
I have generated the devise views and modified the /app/views/devise/sessions/new.html.erb to show this kind of tabbed form.Now functionality wise everything working fine. But there are several issues.
When I am hitting http://localhost:3000/users/sign_up it still shows the devise old signup form. I want to show the same form with the Registration tab activated.
On the Register tab if I submit the form with some error (Empty Email/Password), it is again redirecting to the default device registration form to show up the error messages.
I just want to get rid of this default registration page and want to use my Register tab for all signup purposes.
This question may sounds very basic, but I have no idea how to customize it.
Please help.
Well, I like to make reference to the comment from #max as an answer, so that others could take that as an answer to this question.
I believe you are getting those errors because you are hacking your session views in Devise. The registration view in Devise is at /app/views/devise/registrations/new.html.erb. You have to refactor your code to do away with the errors.
Answer is courtesy of #max
I am currently taking some time to study Devise with Rails 4 for a future app I am planning to create. I have successfully managed to allow users to access to the application via their username or their email.
Now, I would like to inform users whether the username they've picked has already picked up by an other existing user during the signup process and before the user hit the submit button. Github homepage has a three input field form that illustrates my aim.
For that I added to app/models/User.rb the following code
validates_uniqueness_of :username, :email
But this seems to not be sufficient as it only informs the user once the form has been submitted. I imagine that I could try to do this via JS but I am wondering whether there is Ruby only way to achieving this.
Disclaimer: I am fairly intermediate to Rails and a total beginner to Devise.
Thanks for your answers.
There is no ruby only way to do this, you have to use javascript (ajax) to do it, and Rails give you tools to distribute the js to the page and communicate with it.
You have to remember that all the ruby code is executed on the server. The browser only work with the rendered HTML/Css and javascript.