I used config.scoped_views = true in initializers/devise.rb to make Devise use my own views rather than its default views for my two roles (Admin and Subscriber). This worked great, and I went ahead and customized my views.
Then earlier today I added my own controllers that subclass Devise's controllers and told devise to use these controllers in routes.rb using:
devise_for :subscribers, :controllers => {
:registrations => "subscriber_registrations",
:sessions => "subscriber_sessions",
:passwords => "subscriber_sessions"
}
This works nicely, however it seems to have had the unwanted side-effect of making Devise revert back to using its default views for my Subscribers role.
In my logs when I load the login page for Subscribers I can see this:
Rendered /Users/myName/.rvm/gems/ruby-1.9.3-p0/gems/devise-2.1.0/app/views/devise/sessions/new.html.erb
Am I doing something wrong? Do I now need to manually add all the view rendering because I've defined my own controllers?
Related
I'm making some small changes to devise in order to overwrite the layout used and some other things so I decided to create my custom routes with controllers. I only added this to the routes so far:
devise_for :users, :controllers => {
:sessions => "sessions/user",
:registrations => "registrations/user"
}
which is supposed to load the login page when accessed by /users/sign_in and it does it very well. When I try to ajax post to that url in order to validate the user input and login I get this error: NoMethodError (undefined method 'users_url' for #<Sessions::UserController:0x000000041bed98>):
The controller is basic and nothing was changed to overwrote devise logic:
class Sessions::UserController < Devise::SessionsController
layout "login" # The only addition. Rest is handled by devise
end
I had this working for a good while but today I decided to use devise for another model (admins) and I generated it's files using the devise command rails generate devise Admin which completely messed my working code of logging in the users.
Any ideas?
I have a controller JaxDataController for responding to ajax requests which has no associated model.
It has a single routes.rb entry match "/jaxdata/:shape_set_id" => "jax_data#fetch"
I'd like to include the path to this model within a .js.coffee.erb view elsewhere in my app. Are there any routing helpers available for this? Failing that, where should i declare a routing helper to be used in any view?
If you specify the :as option in your route, it will create helpers for that route. Thus:
match "/jaxdata/:shape_set_id" => "jax_data#fetch", :as => :jaxdata
You should then be able to refer to jaxdata_path in your views.
See section 3.6 of this guide: http://guides.rubyonrails.org/routing.html
Im working with ruby 1.9.2, rails 3.1.3, devise 1.5.3, I need to change the devise routes, I already changed the default routes, like login and logout, but I need to change the others routes, for example:
http://localhost:3000/password/new
I need that, when the user click the link did you forget your password? go to:
http://localhost:3000/recovery_password
in my routes I tried:
get "recovery_password", :to => "devise/passwords#new"
get 'recovery_password' => 'devise_passwords#new', :as => :new_user_password
but don't works, please help.
thanks in advance.
try this. It should works. ;)
# change :devise_model to :users, or :admins or any name of your devise model
devise_for :devise_model do
get 'recovery_password' => "devise/passwords#new"
end
and you can use this in view like this.
link_to 'Forgot you password?', recovery_password_url
PS. if you have customize devise controller. You should tell the router first, and change devise controller to your customize controller name.
Following this question, I'd like to know if there is a way to override that new rails behaviour. I run into a security issue with a forgotten view, that was suddenly exposed although the action was not defined in my Controller. I think it'd be better to stop Rails from rendering those not-defined actions and after that cleaning my unused views.
Change your routes for that controller to not route to those actions.
resources :users, :except => [:index, :destroy]
resources :sessions, :only => [:new, :create, :destroy]
Those routes will become non-routable even if the views exists, you can then deal with the views as needed.
I've on a while on rails now and here's the problem I've been having on and on:
When I create a controller through:
"rails generate controller ControllerName ViewName"
I get everything working as I want but if for some reason I create the controller through:
"rails generate controller ControllerName"
and then just add ViewName.html.erb to the folder inside views that has the same name as my controller things would go wrong.
So the concrete case is me writing:
rails generate controller Subjects list show.
Which creates for me:
1.controllers>subjects_controller.rb
2.views>subjects>list.html.erb
3.views>subjects>show.html.erb
So this whole thing works fine.But as I already said if I need another view; let's say "new" I just add "new.html.erb" next to the other *.html.erb files and an action:
def new
end
to my subjects_controller.rb then it won't work.
The two previous views would keep working but any other "*html.erb" created outside the command line wouldn't.
Is there anywhere else where info about views is being stored?.
I'm a Windows 7 user (32 bit).Rails version=3.0.3. WebServer=WEBrick.
Text editor = E-TextEditor
This is most likely caused by your routes not being correctly configured. So it would be helpful to see the content of your routes.rb
In your case I think the best way to configure the routes is to use the resources mapping:
resources :subjects
This will by default create routing for the standard RESTful actions :index, :show, :edit, :update, :new, :create and :destroy.
For more detailed information about the routing, I would recommend Rails Routing from the Outside In