Create a Login page in alchemy using devise

92 views
Skip to first unread message

Antonio Facciolo

unread,
Jan 21, 2015, 11:28:20 AM1/21/15
to alche...@googlegroups.com

Hi everyone,
I want to have a login form inside my website using devise and my own user model.
I installed Alchemy in an existing application with my own user model and authentication.
I have a login page that works using my custom controller action Users::SessionsController#new and my custom view in views/users/sessions/new.html.erb

Now I added the page in alchemy and I wanted to use my own controller, but I got 404 error: "Rendering 404: No route matches {:action=>"new", :controller=>"Users::SessionsController", :urlname=>"login"}"
I tried several times, but without success.

My route file is:

Rails.application.routes.draw do
  devise_for
:users,
    controllers
: {
      sessions
: 'users/sessions',
      registrations
: 'users/registrations'
   
}

  devise_scope
:user do
     
get 'login' => 'users/sessions#new', :as => :login
 
end

  mount
Alchemy::Engine => '/'
end

My layout configuration is:
- name: login
  unique
: true
  cache
: false
  controller
: Users::SessionsController
  action
: new

Antonio Facciolo

unread,
Jan 21, 2015, 11:33:58 AM1/21/15
to alche...@googlegroups.com
The posted route file is without the page in alchemy,
if I add the page then I delete the line "get 'login' => 'users/sessions#new', :as => :login"

Thomas von Deyen

unread,
Jan 21, 2015, 1:03:29 PM1/21/15
to alche...@googlegroups.com
When you are rendering a page you are in the routing scope of Alchemy, but the routes are defined in your main app.

Rails has routing proxy objects for you.

If you want to access your main app routes you have to use:

main_app.login_path

If you are in the scope of your main app or another engine (ie spree) and want to call a alchemy route you have to use:

alchemy.the_named_route
--
You received this message because you are subscribed to the Google Groups "Alchemy CMS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to alchemy-cms...@googlegroups.com.
To post to this group, send email to alche...@googlegroups.com.
Visit this group at http://groups.google.com/group/alchemy-cms.
To view this discussion on the web visit https://groups.google.com/d/msgid/alchemy-cms/24639634-ab80-4b5e-a58f-49953e5371a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Antonio Facciolo

unread,
Jan 22, 2015, 4:36:17 AM1/22/15
to alche...@googlegroups.com
Hi Thomas,
thank you for your reply.

I read the guides, but probably I'm missing something.
I can explain better what I'm trying to do.
The general question is how to create a page in alchemy that includes the view of one action from a main app controller.
In this case I made the login page with devise in my application.
I want to insert the login form inside an alchemy page (in this way I can use the alchemy backend to add other elements to the page and allow the user to change the content and I have the page in the page tree)

These are my attempts:
First I created a login page and the corresponding layout.
1. Inside the layout I copied the code of my login form, but I got this error: undefined local variable or method `resource' for #<#<Class:0x007f8da348df40>:0x007f8da93a9268>
2. I think I had to use the SessionsController to initialize that variable, so I set the controller and the action in the pages_layouts.yml (following this guide) to use my SessionsController, but I got this error: Rendering 404: No route matches {:action=>"new", :controller=>"Users::SessionsController", :urlname=>"login"} in the log
3. I tried to use the same main layout file (application) that I use for alchemy to render the form, but then I got the error: undefined local variable or method `current_alchemy_site' for #<#<Class:0x007f10db1da298>:0x007f10db1d95a0>
I included the Alchemy::ControllerActions and everything worked.
But this is not what I want, in this way I don't have a page in alchemy, I simply use the same layout of the website.

I hope this makes more clear my goal.
Thanks

Antonio
Reply all
Reply to author
Forward
0 new messages