0
votes

I am a Devise fan and have used Devise for many of my Ruby on Rails applications .

I usually follow the below RailCasts for installing and customizing Devise .

http://railscasts.com/episodes/209-introducing-devise

http://railscasts.com/episodes/210-customizing-devise

The video tells us that if we want to customize the views , we need to run the below command -

rails generate devise:views

This creates the views related to authentication in the apps/views/devise folder . We can customize the look and feel .

My questions is - How do we allow multiple views for signing in ? For eg - I want to allow the user to be able to Login from the Root page itself by clicking a Login button on a navbar which leads to a modal box ( overlay / popup ) which allows the user to enter his login credentials , instead of having to visit the predefined pages generated by Devise.

You can have a look at the below link to see the project I am working on now .

http://squilio.heroku.com/ .

Try clicking on the Login button. I would like to have my signin form here .

2

2 Answers

1
votes

the railscast episode you saw is too old ( Apr 12, 2010), latest Devise version is 2.0. so I think some of the features is deprecated.

For your question: If you want to have 2 different pages (e.g. 1 is a dialog/pop up by ajax, another is regular erb page), you have to implement 2 different actions, or at least you have to implement 2 different strategies for them. e.g.

# will render app/views/.../regular_login.html.erb
def regular_login
end 

# render a dialog box only.
def dialog_login
  render :layout => false
end 
1
votes

I found an elegant solution from this article ..

https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app

It shows how we can achieve this by using form_for and posting to user_session_path

<%= form_for("user", :url => user_session_path) do |f| %>
  <%= f.text_field :email %>
  <%= f.password_field :password %>
  <%= f.check_box :remember_me %>
  <%= f.label :remember_me %>
  <%= f.submit 'Sign in' %>
  <%= link_to "Forgot your password?", new_password_path('user') %>
<% end %>