Devise with Rails 4 -
the team behind devise announced via blogpost http://blog.plataformatec.com.br/2013/05/devise-and-rails-4/ releasing version compatible rails 4, calling '3.0 rc'. in same blog post, said it's releasing devise 2.2.4.
i'm trying build rails 4 app. when did gem install devise
, installed 2.2.4, not version compatible rails 4.
fetching: devise-2.2.4.gem (100%)
which assume comments in blogpost strong parameters not going compatible rails 4.
i looked @ devise's github page it's not obvious me how install version compatible rails 4. can assist?
https://github.com/plataformatec/devise
note, tried
gem install devise --version 3.0.0.rc1
but said
error: not find valid gem 'devise' (= 3.0.0.rc1) in repository error: possible alternatives: devise
devise compatible rails 4 out of box of time of answer.
our end goal have users able register, log in , log out of website. we'll create small partial view letting know if we're logged in or out.
install devise gem.
open gemfile
, install devise gem.
gem 'devise'
then in terminal run bundle install
command install gem.
$ bundle install
run devise generators set initial configurations.
run command terminal:
rails generate devise:install
this generator installs initializer configures of devise's available settings.
generate user model.
next need generate our user model. i'm going name user
can name whatever like, replace user
whatever
.
rails generate devise user rake db:migrate
configure default url option development.rb
inside of config/environments/development.rb
, set action mailer's default url localhost:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
make sure have root route declared in routes.rb
you need make sure routes.rb
has default root route - if don't have one, set it!
root to: 'home#index'
create partial view see if we're logged in or not.
inside of views/layouts
folder create file named _user_widget.html.erb
, copy code in:
<% if user_signed_in? %> <p>welcome <%= current_user.email %></p> <%= link_to 'logged in [click logout]', destroy_user_session_path, :method => :delete %> <% else %> <p>you not signed in.</p> <%= link_to 'login', new_user_session_path %> <% end %>
and invoke within layout (views/layouts/application.html.erb
):
<!doctype html> <html> <head> <title>facebookauthtest</title> <%= stylesheet_link_tag "application", media: "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> </head> <body> <p class="notice"><%= notice %></p> <p class="alert"><%= alert %></p> <%= yield %> <%= render 'layouts/user_widget' %> </body> </html>
make sure stop , restart server otherwise find sorts of nasty bugs! it's best restart local server when update gemfile or change in environment configuration file.
with in place, should able sign up, log in , log out own rails website.
if have questions feel free leave comment below , i'll try help.
Comments
Post a Comment