I have a Ruby on Rails app, version 7, with the Devise and Devise Invitable gem installed.
I am currently trying to figure out a way to create two different routes depending on the type of user. User 1 is a basic user who needs one kind of landing page, and User 2 is a special user, who should go to another landing page. Both Users belong to the same model.
Scenario 1:
User 1 is a basic user. We invite User 1 through an email, and this link leads to a landing page with e.g. "Welcome to basic features, please provide your login information"
Scenario 2:
User 2 is a special user. We invite User by generating a URL and then sending it to them manually. The link goes to another landing page with e.g: "Welcome to special features, please provide your login information".
I can't see any way of doing this in the documentation, nor has Googling yielded any results.
I found a way to "cheat" by adding a query parameter to the URL generation. I might go down that path, and decide what to render based on this parameter.
But I was curious if there is a more idiomatic way of doing this.
Related
Let's say I have Blog app built with Rails and on a post created by a user(Author) I have a "Request a chat" button.
I want to build a small function on that post page that when User A presses that button, the page will redirect to or open a chatbox that connect User A with user Author?
Author is a devise registered user and User A is not.
How would I build something like that? Thanks
I think it's weird having a devise registered user and a non devise user unless you mean User A is just an unregistered guest. Either way, it's not a big deal and it can be done.
The way you would put together that system is as follows:
OpenChat # your new data model
OpenChatsController # your new controller
"Request a chat" would create a new OpenChat object, with author and guest A foreign keys. If User A is a guest, you can store a cookie "password" in their browser but generally it's only advisable if the conversation is brief and security isn't a big deal.
Then you would be able to check if there is an open chat between the two users and display it in any page you want, and display messages appropriately.
You will need to look up how to setup a basic chat system (there are a million answers out there that will take you step by step) as that's beyond the scope of this question.
If you are new to Rails, I also recommend Michael Hartl's Ruby on Rails tutorial:
https://www.railstutorial.org/
I have gone a good distance in spring-security-core-2.0-RC5 (SSC) with Grails 2.5, but still a lot to cover. I am wondering how to achieve two tasks. So far and after integrating SSC in my project, I built a dispatcher that takes care of routing users to different landing pages according to their roles. This link shows how I do it. What I am wondering how others are doing is these two tasks:
How to customize the landing page. For example, instead of the typical "Please Login", I need to say "Please login using your provided username and password" plus an image or something. This means I have to override (or overwrite) the existing login page. What is the best way to do this?
The more important. When a user is logged in, I route them to different pages based on their roles, or even log them out if their account is !enabled. However, what I can't do is be in control when the user has no credentials at all. What I would like to do is instead of displaying the typical "Sorry, we were not able to find a user with that username and password.", I would like to intercept the behaviour and perform some actions before redirecting users to the logout/login page (actions like a web service request for example). How can I achieve this please - to be able to make certain tasks on behalf of non-authorized users?
For Task1 (custom login page) you Just have to place a auth.gsp page in 'app/views/login/auth.gsp'
I'm making a Rails application using Devise. On the user profile page, it provides links for the user to update and delete certain elements of their profile. The links are obviously only visible to the signed-in user whose profile it is. The one disadvantage of this is that it doesn't allow the user to view their profile page from the perspective of a visitor, unless they want to log out and navigate to their profile. Some websites offer a "view your profile" link which allows users to view a page from the perspective of someone else. Is there a way to accomplish this with Rails and Devise?
Sure. You are able to create UsersController with show action. Where you will able to display the information you want.
If you want to manage users through CRUD interface there is a wiki page that may help you.
The url to user's profile can looks like /users/:id or you can define custom route such as /user/unique-username (the last example you can achieve using friendly_id gem)
How can I break up the devise signup form into two steps on two different pages?
Page 1: User enters email, clicks submit.
Page 2: User enters password, clicks submit.
This is a common signup flow and I couldn't find any examples, how-tos or questions about it. It seems worth asking for the benefit of all of us beginner Rails monkeys. Of course I'd like to save the email even if the user neglects to enter a password on the second page.
Really appreciate any advice!
You are going to want to use a multi-stage form with sessions. There is a great Railscast here on the topic http://railscasts.com/episodes/217-multistep-forms Sessions are a way of preserving data about a user from one page to the next without the explicit need for you to set his cookies, recognize them etc. Rails sessions take care of all of the recognition.
I'm stuck figuring out the best practice...
I want to create a "following" system in a way that a user can follow a car (getting email updates when car price changes, etc). The part of implementation that's giving me headaches is when I want to introduce lazy registration by only using email.
Everything needs to work as AJAX requests.
In the interface, there will be a button to trigger the follow action, which will check if the user is registered or not. If a user is logged in, create a new CarSubscription item, otherwise display a form where he could type his email address. Once submitted, the form should create a user with no password (if email exists, ask for the password and log in) and then it should create the relationship item.
The challenge here is to use redirection after submission of the form to the CREATE action of the CarSubscriptionController. Since I can't redirect using POST I can't simulate the CREATE or DESTROY action.
The non-RESTful solution would be to create 2 actions under cars_controller: follow and unfollow and let them do the logic of creating entries and deleting them. That would enable me to just store the request path and use it after the user enters their email and logs in.
How can I achieve what I want using RESTful resources?
After trying to describe my problem here, it seems it's way too complicated and I am indeed very stuck... There are 3 different controllers and possibly 4 requests in this scenario.
Any help would be tremendously appreciated!
Please see my flow chart below:
Not an expert here, I don't know if it's the best solution, but what I have done in similar situation is :
In your controller, respond with javascript instead of redirecting the user
In your javascript file, use $.post(...) to issue a POST to your controller action
Et voilĂ !
You can also use ActiveResource to achieve this, but I actually never tried that solution : http://api.rubyonrails.org/classes/ActiveResource/Base.html#label-Custom+REST+methods
Person.new(:name => 'Ryan').post(:register)
Hope this helps
I had a very similar need and had trouble pulling the various bits of info on how to do this with Devise and Rails together into a working example. Here's a fully working example based on Rails 4, Ruby 2, and Devise 3.0:
https://github.com/mwlang/lazy_registration_demos