Ruby on Rails / gem devise / login page in a modal
I would like to have the login page in a modal (instead of opening a separate page). I am using the gem devise to create account.
In views/layouts/application.html.erb, I created the code to call for the modal:
<div id="openModal" class="modalDialog">
<div>
<a href="#close" title="Close" class="close">X</a>
<%=render 'devise/sessions/newsession'%>
</div>
</div>
Then in views/devise/sessions/_newsession.html.erb
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Log in" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
I am getting the following error message:
undefined local variable or method `resource' for <#:0x007fafd8bc60f8>
It looks like devise is not recognized in the page application.html.erb.
Would you understand where the error come from?
ruby-on-rails devise
add a comment |
I would like to have the login page in a modal (instead of opening a separate page). I am using the gem devise to create account.
In views/layouts/application.html.erb, I created the code to call for the modal:
<div id="openModal" class="modalDialog">
<div>
<a href="#close" title="Close" class="close">X</a>
<%=render 'devise/sessions/newsession'%>
</div>
</div>
Then in views/devise/sessions/_newsession.html.erb
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Log in" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
I am getting the following error message:
undefined local variable or method `resource' for <#:0x007fafd8bc60f8>
It looks like devise is not recognized in the page application.html.erb.
Would you understand where the error come from?
ruby-on-rails devise
add a comment |
I would like to have the login page in a modal (instead of opening a separate page). I am using the gem devise to create account.
In views/layouts/application.html.erb, I created the code to call for the modal:
<div id="openModal" class="modalDialog">
<div>
<a href="#close" title="Close" class="close">X</a>
<%=render 'devise/sessions/newsession'%>
</div>
</div>
Then in views/devise/sessions/_newsession.html.erb
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Log in" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
I am getting the following error message:
undefined local variable or method `resource' for <#:0x007fafd8bc60f8>
It looks like devise is not recognized in the page application.html.erb.
Would you understand where the error come from?
ruby-on-rails devise
I would like to have the login page in a modal (instead of opening a separate page). I am using the gem devise to create account.
In views/layouts/application.html.erb, I created the code to call for the modal:
<div id="openModal" class="modalDialog">
<div>
<a href="#close" title="Close" class="close">X</a>
<%=render 'devise/sessions/newsession'%>
</div>
</div>
Then in views/devise/sessions/_newsession.html.erb
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Log in" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
I am getting the following error message:
undefined local variable or method `resource' for <#:0x007fafd8bc60f8>
It looks like devise is not recognized in the page application.html.erb.
Would you understand where the error come from?
ruby-on-rails devise
ruby-on-rails devise
edited Sep 24 '17 at 9:49


Sebastian Palma
15.6k41933
15.6k41933
asked Sep 24 '17 at 8:37
AntoineAntoine
247
247
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
As you're rendering the login form which uses a resource
and resource_name
variables which aren't initialized from "outside" a devise controller, what you can do is to add them to your ApplicationHelper file to be able to work with them from your current controller or any other.
Try editing your helper file adding the resource
, resource_name
and devise_mapping
:
module ApplicationHelper
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
Just to add that if you want to render the sessions#new view file you can simply render this file as render file: 'devise/sessions/new'
, if you've run the devise:views
command, this would help you to maintain just one form instead creating a new one, of course, is just a suggestion.
add a comment |
1+ for Sebastians answer. Another way is pass the values to RenderingHelper:
<%= render 'layouts/modal/myModal', resource: User.new, resource_name: :user, devise_mapping: Devise.mappings[:user] %>
add a comment |
Used this in the past, worked great:
<div class="modal custom fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h2 class="text-center">Connexion</h2>
</div>
<div class="modal-body">
<%= form_for(:user, :url => session_path(:user)) do |f| %>
<div class="email-container">
<%= f.text_field :email, :class =>"form-control",placeholder: "Email", value:"" %>
</div>
<div class="password-container">
<%= f.password_field :password,:label =>"Password", :class =>"form-control", placeholder:"Password", value:""%>
</div>
<%= f.submit 'Login', :class =>"form-control" %>
<%= f.check_box :remember_me, label: "Remember me", value: "true" %>
<%= f.label :remember_me %>
<% end %>
</div>
</div>
</div>
</div>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46388195%2fruby-on-rails-gem-devise-login-page-in-a-modal%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
As you're rendering the login form which uses a resource
and resource_name
variables which aren't initialized from "outside" a devise controller, what you can do is to add them to your ApplicationHelper file to be able to work with them from your current controller or any other.
Try editing your helper file adding the resource
, resource_name
and devise_mapping
:
module ApplicationHelper
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
Just to add that if you want to render the sessions#new view file you can simply render this file as render file: 'devise/sessions/new'
, if you've run the devise:views
command, this would help you to maintain just one form instead creating a new one, of course, is just a suggestion.
add a comment |
As you're rendering the login form which uses a resource
and resource_name
variables which aren't initialized from "outside" a devise controller, what you can do is to add them to your ApplicationHelper file to be able to work with them from your current controller or any other.
Try editing your helper file adding the resource
, resource_name
and devise_mapping
:
module ApplicationHelper
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
Just to add that if you want to render the sessions#new view file you can simply render this file as render file: 'devise/sessions/new'
, if you've run the devise:views
command, this would help you to maintain just one form instead creating a new one, of course, is just a suggestion.
add a comment |
As you're rendering the login form which uses a resource
and resource_name
variables which aren't initialized from "outside" a devise controller, what you can do is to add them to your ApplicationHelper file to be able to work with them from your current controller or any other.
Try editing your helper file adding the resource
, resource_name
and devise_mapping
:
module ApplicationHelper
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
Just to add that if you want to render the sessions#new view file you can simply render this file as render file: 'devise/sessions/new'
, if you've run the devise:views
command, this would help you to maintain just one form instead creating a new one, of course, is just a suggestion.
As you're rendering the login form which uses a resource
and resource_name
variables which aren't initialized from "outside" a devise controller, what you can do is to add them to your ApplicationHelper file to be able to work with them from your current controller or any other.
Try editing your helper file adding the resource
, resource_name
and devise_mapping
:
module ApplicationHelper
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
Just to add that if you want to render the sessions#new view file you can simply render this file as render file: 'devise/sessions/new'
, if you've run the devise:views
command, this would help you to maintain just one form instead creating a new one, of course, is just a suggestion.
answered Sep 24 '17 at 8:51


Sebastian PalmaSebastian Palma
15.6k41933
15.6k41933
add a comment |
add a comment |
1+ for Sebastians answer. Another way is pass the values to RenderingHelper:
<%= render 'layouts/modal/myModal', resource: User.new, resource_name: :user, devise_mapping: Devise.mappings[:user] %>
add a comment |
1+ for Sebastians answer. Another way is pass the values to RenderingHelper:
<%= render 'layouts/modal/myModal', resource: User.new, resource_name: :user, devise_mapping: Devise.mappings[:user] %>
add a comment |
1+ for Sebastians answer. Another way is pass the values to RenderingHelper:
<%= render 'layouts/modal/myModal', resource: User.new, resource_name: :user, devise_mapping: Devise.mappings[:user] %>
1+ for Sebastians answer. Another way is pass the values to RenderingHelper:
<%= render 'layouts/modal/myModal', resource: User.new, resource_name: :user, devise_mapping: Devise.mappings[:user] %>
answered Nov 21 '18 at 15:31
SkatEddySkatEddy
5614
5614
add a comment |
add a comment |
Used this in the past, worked great:
<div class="modal custom fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h2 class="text-center">Connexion</h2>
</div>
<div class="modal-body">
<%= form_for(:user, :url => session_path(:user)) do |f| %>
<div class="email-container">
<%= f.text_field :email, :class =>"form-control",placeholder: "Email", value:"" %>
</div>
<div class="password-container">
<%= f.password_field :password,:label =>"Password", :class =>"form-control", placeholder:"Password", value:""%>
</div>
<%= f.submit 'Login', :class =>"form-control" %>
<%= f.check_box :remember_me, label: "Remember me", value: "true" %>
<%= f.label :remember_me %>
<% end %>
</div>
</div>
</div>
</div>
add a comment |
Used this in the past, worked great:
<div class="modal custom fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h2 class="text-center">Connexion</h2>
</div>
<div class="modal-body">
<%= form_for(:user, :url => session_path(:user)) do |f| %>
<div class="email-container">
<%= f.text_field :email, :class =>"form-control",placeholder: "Email", value:"" %>
</div>
<div class="password-container">
<%= f.password_field :password,:label =>"Password", :class =>"form-control", placeholder:"Password", value:""%>
</div>
<%= f.submit 'Login', :class =>"form-control" %>
<%= f.check_box :remember_me, label: "Remember me", value: "true" %>
<%= f.label :remember_me %>
<% end %>
</div>
</div>
</div>
</div>
add a comment |
Used this in the past, worked great:
<div class="modal custom fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h2 class="text-center">Connexion</h2>
</div>
<div class="modal-body">
<%= form_for(:user, :url => session_path(:user)) do |f| %>
<div class="email-container">
<%= f.text_field :email, :class =>"form-control",placeholder: "Email", value:"" %>
</div>
<div class="password-container">
<%= f.password_field :password,:label =>"Password", :class =>"form-control", placeholder:"Password", value:""%>
</div>
<%= f.submit 'Login', :class =>"form-control" %>
<%= f.check_box :remember_me, label: "Remember me", value: "true" %>
<%= f.label :remember_me %>
<% end %>
</div>
</div>
</div>
</div>
Used this in the past, worked great:
<div class="modal custom fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h2 class="text-center">Connexion</h2>
</div>
<div class="modal-body">
<%= form_for(:user, :url => session_path(:user)) do |f| %>
<div class="email-container">
<%= f.text_field :email, :class =>"form-control",placeholder: "Email", value:"" %>
</div>
<div class="password-container">
<%= f.password_field :password,:label =>"Password", :class =>"form-control", placeholder:"Password", value:""%>
</div>
<%= f.submit 'Login', :class =>"form-control" %>
<%= f.check_box :remember_me, label: "Remember me", value: "true" %>
<%= f.label :remember_me %>
<% end %>
</div>
</div>
</div>
</div>
answered Sep 24 '17 at 8:44
Graham SlickGraham Slick
2,84132755
2,84132755
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46388195%2fruby-on-rails-gem-devise-login-page-in-a-modal%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown