How to send information from devise user using mailer? - ruby-on-rails

I'm using devise gem and I want to set up a mailer to send information from user to my gmail account and also the user receive a confirmation.

Please be a bit more specific in the first part of your question. What do you exactly want to do?
For the confirmation, the devise gem has a confimrable module which might help you further. Look here: https://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Confirmable

Related

Devise skip_confirmation! method confirms user

In my Ruby on Rails application I have multi step with wicked gem to create customer registration. I want to send confirmation at the last step so in my controller I use devise method:
#customer.skip_confirmation!
But this method is not sending confirmation email and automatically confirm customer. I don't want to have confirmed customer when he didn't click the link in mail. Is there any way to solve this problem?
There is a good answer here:
Rails 3 with Devise for Authentication - How do I manually create a user?
It explains that skip_confirmation! method sets confirmed_at, and also supplies a workaround which allows you to skip confirmation without confirming the user.
If you don't want confirmation to be sent on create, neither a code to
be generated, call skip_confirmation!
if you have added in your user.rb (model) the confirmable module, than the confirmation will be send by it self, right after the user have been created. So you don't need to add something in your controller other than #user.create!

Devise: Place a variable in the confirmation email

I am trying to customise the confirmation email in order to pass an extra variable than the resource and confirmation token.
In particular what I want is to get the existing (soon to be overridden) email of the user passed into the confirmation email so that when the user clicks on the confirmation link, the page he goes to will have the user's old email in the parameters.
I'm not sure where I will need to make this change exactly (maybe mailer view or devise mailer?) and also what is the best way to override this in my rails app without touching the devise gem at all?
Or maybe there is even a better way I can get the user's old email after he confirms on the link but, as far as I'm aware, once that happens the old email is gone for good.
Use rails generate devise:views.
This will generate all the views that Devise uses internally so you can make your modifications.
NOTE
This will generate erb templates. If you wish to use haml or anything else. Here is a tutorial on how you can go about this process.

Devise and simple-private-messages implementation

I want to build a user inbox system and choosing this simple-private-messages gem as the backbone. However, the documentation of this gem is rather primitive.
I've generated the scaffold of this gem, however, I don't know what key the gem is used to define the recipient/sender.
I want the current_user is able to message a particular user via the link of its profile page and then it will automatically fill the username into the "to" field.
Would anyone please construct a demo app illustrating the implementation of this gem, thanks a lot.
Please advise.

Devise, how to downcase emails on save?

right now users can log into devise with their email & password. Problem is that email is saved case sensitive which is confusing users.
Does Devise have a setting to downcase the email, something like downcase_keys?
I know I can manually do this with a before_save but I thought I had read devise had this as an option out of the box. I just can't find the doc on how to set it to downcase?
Thanks
You should be able to configure it using case_insensitive_keys in config/initializers/devise.rb (see here).

Email confirmation in Rails without using any existing authentication gems/plugins

I'm working on this alerting service in Rails. And really, all I need to do is, when a user signs up, send a confirmation email to the user. And upon confirmation from the user, activate the user. I tried playing around with Matt Hooks' Authlogic email activation tutorial, but its really leading nowhere. So , any ideas how I can do this with minimum fuss ?
Thanks !
UPDATE
So how i got devise to do the job for me is :
Install the gem.
Create a migration for devise's confirmable fields.
Specify
devise :confirmable
in your model.
Create a confirm method in the relevant controller(and a route for that method) which would update the confirmed_at attribute of the relevant model.
The devise generator creates a few views for you, one which is confirmation_instructions.html.erb. Customize the path there.
I used Rails 2.3.2 and I 've used this method along with Authlogic's authentication and it worked well. I do plan to switch to devise completely.
In all honesty, I wanted to accept both answers (unfortunately I can't do that), but its just that the devise solution seemed a easier solution.
Assuming given the title that you definitely want to avoid Devise, Authlogic and friends, here's what I think you need to do:
Create 'confirmation code' and 'confirmed' attributes in your user model.
Create a new controller method on your user controller that expects a user id and confirmation code, looks up the user and then checks if the code in the parameter matches the code stored in the DB. If so, it clears the code and sets confirmed = true.
Create a route that maps e.g. /users/1/confirm/code to your new controller method.
Create an ActionMailer template for the e-mail you want to send. This should accept a user as a parameter, and use the confirmation code of the user to send a mail containing a link to your new route.
Create an observer for your user model. If the record is created or the e-mail address modified, then generate a random confirmation code, set it into the model and clear the confirmed flag. Then trigger your ActionMailer.
Create a helper method which allows views to check if the current user is confirmed.
Use this method to enable/disable functionality as appropriate. Remember to protect your controller methods as appropriate as well as your view logic.
You could also make use of scopes for selecting users.
class User < ActiveRecord::Base
scope :certified, where(:certified => true)
end
And then in your code:
#user = User.certified.find_by_username(foo)
Devise is an other excellent authentication gem that comes with email activation build in, perhaps you could give it a go.

Resources