Problems signing out with Devise in Rails 4 - devise

I'm having problems signing out in my app.
The error that it's giving me is:
Template is missing
Missing template users/destroy, application/destroy with {:locale=> [:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}.
Searched in: *"/home/gregb/workspace/Sandbox/site/app/views"
* "/home/gregb/.rvm/gems/ruby-2.2.0/gems/devise-i18n-views-0.3.6/app/views"
* "/home/gregb/.rvm/gems/ruby-2.2.0/gems/devise-3.5.2/app/views"
Any help would be greatly appreciated.

If you're using devise, then that doesnt seem to me like the directory where the view exists.
did you do
rails g devise:views
or create your custom views?
there's no destroy.html.erb file in devise.
but if you want to create one , I'd suggest you to create the destroy action in a newly created UsersController, then in the routes you have to place the
resources :users, only: [:destroy]
under the
devise_for :users
in order for it to be accessible. Then rake routes and find the right route. That should create the destroy action route for you.Create views in the app/views/users/destroy.html.erb and that should hopefully do it for you.

Related

Cannot find application.html.haml in a new Rails 3 app

I want to create Rails 3 app just to update myself, but I have strange issue.
I have created welcome#index action using
rails generate controller welcome#index
(I have haml-rails gem) and I observe that a new view index.html.haml has been created. This action is my root_path, so in localhost:3000 I get content of this view.
I had application.html.erb which I have changed manually to application.html.haml and I have added layout 'application' in ApplicationController, but I get
Template is missing
Missing template layouts/application with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :haml]}
now, any ideas why ?
Maybe some code snippets:
class ApplicationController < ActionController::Base
layout "application"
protect_from_forgery
end
the file is in place:
mkk:~/projects/rails/gifts/app/views/layouts$ ls
application.html.html
Your ls shows the layout file is called application.html.html, change it to application.html.haml.

Rails 3 with devise undefined method `users_url`

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?

rails routes gives an error - wrong controller seems to be called

I can't figure out what's wrong with my routes. I'm very new to rails (and programming) so it could be something very simple.
Clicking on my home page gives the following error -
Routing Error
No route matches {:action=>"show", :controller=>"bets"}
Try running rake routes for more information on available routes.
This is my routes.rb
root :to => 'pages#home'
resources :bets
resources :bettingevents
get '/bet' => 'bets#index'
get '/bettingevent' => 'bettingevents#index'
The show function in my bets controller has
def show
redirect_to(bets_path)
end
localhost:3000/bets is fine, with create, update, delete, edit routes working correctly. My pages controller has been working perfectly till I added the bets routes.
If i remove resources :bets the homepage works all right, but none of the bets routes work.
What am I doing wrong? Thanks

Rails 3 - index action not loading by default on controller

Now i have a fresh rails 3 install running over rvm 1.9.2
I generated a controller using the follow instruction:
rails generate controller blog index
The output is
create app/controllers/blog_controller.rb
route get "blog/index"
invoke erb
create app/views/blog
create app/views/blog/index.html.erb
invoke test_unit
create test/functional/blog_controller_test.rb
invoke helper
create app/helpers/blog_helper.rb
invoke test_unit
create test/unit/helpers/blog_helper_test.rb
but in browser when i try to get to http://localhost:3000/blog i get:
No route matches "/blog"
but if i type http://localhost:3000/blog/index
it renders the index view.
doesn't it works like Rails 2? where i get to the index view by default with just putting the controller name on the url ?
thanks.
If you look into routes.rb you'll see
get "/blog/index" => "blog#index"
So just remove it with
get "/blog" => "blog#index"
or you can use resources here.
But only question: why do you use singular form? It is nonsensical to call index to singular noun. You should use or "blog#show" as a resource or "blogs#index" as a resources.
Conventions in Rails is a kind of basement. Don't break them if you can follow them
For rails 3:
match '/blog', :controller => 'blog', :action => 'index'
Rails generate does not generate resources for your controller by default. You specified one action for your controller, 'index', so in your case you end up with this in config/routes.rb:
Blog::Application.routes.draw do
get "blog/index"
The simplest thing to do would be to change this to:
get "blog", :to => 'blog#index'
ian.
This is a guess, based on my experience with Rails 2, but here's what I think is happening:
If you'd generated your controller with the scaffold option (that's still in Rails 3, right?), it would have created a model in addition to your controller, and added the corresponding routes via a call to map.resources (or Rails 3 equivalent) - this last bit is what gives you the /models routes you're expecting.
But since you just generated the controller, no model was created, and thus Rails doesn't put in a map.resources statement in routes.rb - map.resources really only makes sense when there's a model underlying your controller. In fact, I don't think it adds any special routes when you generate a controller; you're getting to your index by one of the default routes: /:controller/:action.
So if you want to get to your index from /blog, you'll have to add the route yourself. Luckily, it should be a one-liner.
Hope this helps!
PS: And if you're paranoid, you'll want to disable those default routes before you go to production - they allow GET requests to trigger actions that change your database (e.g. GET:/blog/destroy), opening you up to Cross-Site Request Forgery attacks.
Add this to your routes.rb file match ':controller(/:action(/:id))(.:format)'
It's better if you add it at the bottom of the routes.rb file.
The problem with this approach is that it will make all your actions available through get request. So be careful with that.
Instead of manual routing you can go to /app/controllers/application_controller.rb and add a blank index method
def index
end
make sure your generated controller extends the application controller, and boom all your generated controllers do what you want
Tested on Rails 3.2.*

Rails app doesn't see my views

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