Devise logout not working, giving routing error - ruby-on-rails-3.1

<%= link_to "Sign Out", destroy_user_session_path,:method => :delete%>
destroy_user_session DELETE /users/logout(.:format) devise/sessions#destroy
Routing Error
No route matches [GET] "/users/logout"
devise_for :users, path_names: {sign_in: "login", sign_out: "logout"},
controllers: {omniauth_callbacks: "omniauth_callbacks"}

Your link_to tag includes :method => :delete as it should but your error message says that the request is being made with the GET method. This won't work, since the route is only for DELETE requests.
Did you click the "sign out" link and immediately get the error message? I'd expect that your answer is no. It's more likely that you're trying to visit /users/logout directly in your browser, without using the link. That would make it a GET request instead of DELETE.

Related

Adding custom form actions in ActiveAdmin

I'm using ActiveAdmin to add google OAuth credentials to a record. The client ID and Client Secret are added via record/1/edit, and I use those to generate a link to allow access. This link appears in record/view. I am trynig to find a way for the Administrator to enter the code returned by google oauth into the portal so that I can use it to generate credentials.
My current attempt looks something like this
row "Code from Google OAuth" do
form do |f|
label "Google Auth Code:"
input :code, :label => "Code", :hint => "Code returned by google auth"
f.action :submit
end
I get an "undefined method: action" error form this code. Any ideas on how to return user input as a parameter?
form is an Arbre tag that maps directly to HTML, in which case action is an attribute, eg.
form(action: '/someroute', method: :patch) do ... end
If you want to embed a Rails or Formtastic form you would use form_for or active_admin_form_for respectively.

Error after installing devise in rails

I installed devise for rails 4 and followed all the necessary instructions.
I have the root 'home/index'.
In my home/index view erb is the following.
<%= link_to 'Sign In' , new_user_session_path%><br>
<%= link_to 'Sign Up' , new_user_registration_path%>
So when I click on the Sign_in link. I get the following error.
Errno::ENOENT in Devise::RegistrationsController#new
No such file or directory - getcwd
There was a similar question asked before but did not solve my problem. This problem only started coming up recently and never occured when I used rails for my other apps.
did you generate the devise views?
rails generate devise:views

Rails 3.1 link_to not showing confirmation or destroying properly

I've been plowing through the chapters at railstutorial.org and been using Rails 3.1.3 because I'm crazy and/or wanted a challenge. I managed to figure out most version problems easily but this one stumped me for a while.
In 10.4.2, Michael Hartl uses the following code to delete users:
<%= link_to "delete", user, :method => :delete, :confirm => "You sure?",
:title => "Delete #{user.name}" %>
It doesn't work properly if you test it in the browser (chrome) and instead sends you to that user page.
It is supposed to work if you include this:
<%= javascript_include_tag :defaults %>
but it fails with Rails 3.1 (it should work for Rails 3.0 though, or so I hear).
So for all of you pulling out your hair for using Rails 3.1, here's the solution.
<%= javascript_include_tag "application" %>
Using "application" instead of :defaults solves this problem, delete and confirm should work, now get back to coding!
Special thanks to George Shaw for this answer over on https://stackoverflow.com/a/8350158/1127011 .
And it case you were wondering, title is for mouseover only.
The a HTML tag will always fire the GET method. Rails uses the Javascript driver to replace the HTTP verb. The link_to method will fallback any method (post, put and delete) to get (corresponding to the show action) when :
Javascript has been disabled by the user
for some reason, Rails unobtrusive javascript driver is not handling the link properly
See http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html
I suspect the second reason to be the issue. Make sure the jquery.js, application.js, jquery_ujs.js file are included.
Instead of link_to, you could try to use button_to which creates a form allowing put, post and delete methods without Javascript enabled.

Using Cucumber to test controller without a view in Rails

I'm a ruby/rails newbie and the application I'm developing starts with a HTTP post from another website which passes in some data and then displays some data capture screens before calling a web service.
I want to start this project using an outside in approach using Cucumber for integration tests and rspec for functional/unit testing.
Using Cucumber how do I simulate the post from the external website so that I can test the flows with the application.
It doesn't really matter to the application where the call originated; only that the parameters supplied match the expected ones from the referring page. If you depend on a specific HTTP_REFERER being set, check out this answer on how to set a header in Cucumber.
add_headers({'HTTP_REFERER' => 'http://referringsite.com'})
Since you already know which query parameters/headers your app expects from the referring site you can create a setup block that will set these appropriately for each cuke.
If you are using Cucumber with Capybara you can do a HTTP POST like this.
When /^I sign in$/ do
#user = Factory(:user)
get "/login"
page.driver.post sessions_path, :username => #user.username, :password => #user.password
end
Alternatively if you have a view it would be something like this.
When /^I sign in$/ do
#user = Factory(:user)
visit "/login"
fill_in "Username", :with => #user.username
fill_in "Password", :with => #user.password
click_button "Log in"
end

ActionController::RoutingError (uninitialized constant User::UsersController) in heroku (but everything works in local)

I am trying to run my app in heroku but I get this error when trying to signup or even access devise's login page:
ActionController::RoutingError (uninitialized constant User::UsersController)
Is this a devise bug or a server setting i missed in heroku?
I am running a rails3.1 app in a cedar stack by the way and loading the index page is good, but if I try to login or sign up, it blows.
The signup form DOES show, but when I submit, that's when it blows. I checked the logs and it did POST to the controller but GETting the resulting page(when redirected I guess) blows it up.
Any help?
EDIT
here are my routes:
root :to => "home#index"
devise_for :users
namespace :user do
root :to => "users#welcome"
end
resources :users, :only => :show
A heroku support person also asked about my routes but why does it happen in production only? Also I don't think there's any problem with the routes...is there?
I found the you do not need to remove the default root for when a user logs in. So replace the namespace call and use the following:
match 'users' => 'users#welcome', :as => 'user_root'
This way you can still have two "home" pages. It worked for me.
https://github.com/plataformatec/devise/wiki/How-To%3a-Redirect-to-a-specific-page-on-successful-sign-in
This is your problem:
namespace :user do
root :to => "users#welcome"
end
Can you remove this?
I got the same error. Error was only reproducible in Heroku, not locally. What I realized is that while I had added the resource to routes and pushed that, all the generated scaffold was still lying locally. Once I added all the generated stuff to git and pushed, worked fine on Heroku.

Resources