Basic::Initial::Rails4
TODO: Write a gem description
Installation
Add this line to your application's Gemfile:
gem 'basic-initial-rails4'
Add permited omniauth gem in you Gemfile:
gem 'omniauth-facebook'
gem 'omniauth-twitter'
gem 'omniauth-linkedin'
gem 'omniauth-github'
You can view documentation for each omniauth gem in:
And then execute:
$ bundle
Or install it yourself as:
$ gem install basic-initial-rails4
Usage
execute:
$ rails generate model user name email password_digest id_facebook id_twitter id_linkedin id_github
$ rails generate binstall
This proccess write and create an important methods and files
- config/initializers/mail.rb
ActionMailer::Base.smtp_settings = {
user_name: 'example@example.com',
password: 'example',
address: 'smtp_settings',
port: 587,
enable_starttls: true
}
Transport Layer Security
class Notifier < ActionMailer::Base
from_address = ActionMailer::Base.smtp_settings[:user_name]
default from: "App Name <#{from_address}"
def mail_method(mail)
subject = "#{mail.subject} from App name"
mail(to: mail.email, subject: subject)
end
end
- config/environments/development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
This file have a:
config.action_mailer.raise_delivery_errors = false
Change to true
config.action_mailer.raise_delivery_errors = true
-
app/notifier/mail_method.html.rb
Empty file represent the theme for mail send
-
app/controllers/application_controller.rb
before_filter :load_initial
def load_initial
@init_twitter = nil
@init_github = nil
@init_facebook = nil
@init_linkedin = nil
end
def is_login!
if session[:user_id].nil?
redirect_to sessions_new_path, notice: 'You need login to load this section'
elsif $current_user.nil?
$current_user = User.find_by_id(session[:user_id])
end
end
get 'sessions/new'
post 'sessions/new', to: 'sessions#create'
get 'sessions/destroy', to: 'sessions#logout'
resources :users, only: [:index, :create, :new]
get '/auth/:provider/callback', to: 'sessions#create'
get '/auth/failure', to: 'sessions#failure'
has_secure_password
validates :name, presence: true, uniqueness: true, length: { minimum: 5, maximum: 18}, format: {with: /[a-zA-Z\s]/}
validates :password, presence: true, length: { minimum: 8, maximum: 24}
validates :email, presence: true, uniqueness: true, format: {with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
Notes of usage
Your need a root to in routes.rb file
root to: 'controller_name#method_name'
spec notes
So test a controller with is_login! before_filter you need include
session[:user_id] = user.id
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request