0

In my views/devise/sessions/new.erb.html file I have the following line

> <%= form_for(resource, :as => resource_name, :url =>
> session_path(resource_name), :html => { :class => "form-horizontal
> well"}) do |f| %>

This works fine, but if I try to put this form on my homepage, I get an error...

undefined local variable or method `resource' for #<#<Class:0x2950e78>:0x563118>

What do I need to do to get this working? Or is there documentation for Devise regarding this?

HelloWorld
  • 4,251
  • 8
  • 36
  • 60
  • I think I may have found it - https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app – HelloWorld Jan 23 '13 at 18:31
  • This is a duplicate question - http://stackoverflow.com/questions/13079079/how-to-put-a-login-form-in-the-header-for-devise-and-rails?rq=1 – HelloWorld Jan 23 '13 at 18:37

2 Answers2

1

Devise takes a bit of an agnostic approach to the objects it authenticates, resource is just a proxy for the mappings you define using the devise_for in your routes file. That said, if you already know the name of the resource you can just specify it manually, a la:

<%= form_for("user", :url => user_session_path, :html => { :class => "form-horizontal well"}) do |f|%>

Alternatively, you can simply define the respective resource and resource_name methods inside of your controller as shown in the documentation you linked.

Noz
  • 6,216
  • 3
  • 47
  • 82
0

You can also add the Devise helper methods to your controller_helper.rb. for the home controller I believe it is application_helper.rb.

An example is here

Community
  • 1
  • 1
grandocu
  • 326
  • 1
  • 4