Ruby on Rails Form_for resource in other file -


well have problem form_for,with gem devise. before have in users/session/new.html.erb

<h2>log in</h2>    <%= form_for(resource, as: resource_name, url: session_path(resource_name), html: {class: 'form-horizontal'}) |f| %>  <div class="form-group">      <%= f.label :email, class: "col-sm-2 control-label" %>      <div class="col-sm-6">          <%= f.email_field :email, autofocus: true , class: "form-control" %>      </div>  </div>

but try code in bootstrap modal, in other file, in app/views/layouts/_header.html.erb because have button "log in".

when put there -> undefined local variable or method `resource' for

a solution? or need put code?

the trick defining resource_name, resource , devise_mapping helper methods in applicationhelper. assuming devise model called user, place following methods in application helper:

# application_helper.rb  module applicationhelper   def resource_name     :user   end    def resource     @resource ||= user.new   end    def devise_mapping     @devise_mapping ||= devise.mappings[:user]   end end 

Popular posts from this blog