Devise displaying Warning - ruby-on-rails-3

I set up a simple Authentication system based on Railscasts #209 and #210.
When i type http://localhost:3000/users/registration/sign_up , the signup page is displayed.But, a warning accompanies it:
DEPRECATION WARNING: f.error_messages was removed from Rails and is now available as a plugin. Please install it with `rails plugin install git://github.com/rails/dynamic_form.git`. (called from realtime at C:/Ruby192/lib/ruby/1.9.1/benchmark.rb:309)
How can i fix this issue?
Also, how to customize this route in devise?
something like localhost:3000/sign_up is a lot better.

OK, well, to answer your first question, you can either install the plugin as detailed in the error message or you can do something like this:
<%- #user.errors.full_messages.each do |message| -%>
<p><%= message %></p>
<%- end -%>
Basically, it'll run through all the messages and print them out.
To answer your second question, you can do something like this in your routes.rb:
devise_for :users
devise_scope :user do
get '/login' => 'devise/sessions#new'
get '/logout' => 'devise/sessions#destroy'
end

Related

rails3 authlogic-connect unknown attribute: oauth_provider

I'm trying to use the authlogic-connect plugin to add oauth support to my web app but I'm getting the error:
unknown attribute: oauth_provider
when UsersController#create is called. It is failing when I try to create a new user from the parameters that are being passed in:
#user = User.new(params[:user])
Sure enough, the parameters include this attribute:
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"lHX2BTFTd5xITTfY/X8A9R3vca3YaRuHFoWdqy8ZPik=",
"user"=>{"oauth_provider"=>"linkedin"},
"commit"=>"LinkIn"}
From the documentation, I assumed that this was what you are supposed to do:
Second, if you are using Oauth, you must include an input with name oauth_provider
and value twitter or whatever other provider you might want (see example apps for
dynamic example).
Any ideas on how this is supposed to work? All of the example forms are in yaml - which I don't know - and I'm trying to create this from using embedded ruby code. Here's the form that I'm using:
<!-- authlogic-connect hack -->
<%= form_for #user do |f| %>
<%= f.radio_button(:oauth_provider, "linkedin") %>
<%= f.label(:oauth_provider_linkedin, "Link In Fool") %>
<%= f.submit :value => "LinkIn" %>
<% end %>
As Dimitry pointed out, the best answer to this question is to use devise + omniauth instead of trying to get authlogic to work. Authlogic simply doesn't support rails3. I spent at least a week trying to get authlogic to work the way I wanted and I never solved the problem. I then spent a few hours getting devise + omniauth to do exactly what I want (i.e. you can create an account with LinkedIn or on the sight and you can associate them together so that you can login with LinkedIn or with email and password to the same account).

Google suggest and auto complete with jquery/ajax in Rails app

I would like to get some ref to use Jquery in Rails app.
At the moment, I am stuck to find the things to enable google suggest in text box and autocomplete in Rails app. Any help/suggestions/ref would be of great help.
I did a short search on auto-complete with Rails earlier today and these are the best links I found:
http://github.com/crowdint/rails3-jquery-autocomplete and http://github.com/crowdint/rails3-jquery-autocomplete-app
http://blog.jackhq.com/posts/3-how-to-add-jquery-autocomplete-to-your-rails-forms-in-a-restful-way
http://code.google.com/p/jquery-autocomplete/
Edit: I just implemented the first link in my app, works flawless so far. I had minor problems with the documentation though, this works for me (on typing AutoComplete starts after the second character):
Model named Category, has an attribute name:
controller:
class UsersController < ApplicationController
autocomplete :category, :name
...
routes:
get 'users/autocomplete_category_name'
view:
<%= form_tag 'users/index' do %>
<%= autocomplete_field_tag 'address', '', users_autocomplete_category_name_path, :size => 75 %>
<% end %>

Rails login partial in different controller

Hey,
I'm pretty new to rails and for learning effect, I try to implement my own authorization system.
Right now I'm having a Page Controller to control some static pages and nothing more, and a Session Controller where I plan to implement most of the authorization process.
My problem is, I have no clue how to get my partial to use the sessions-controller, when I add it to one of the static pages controlled by the pages controller.
It stated out with this http://ruby.railstutorial.org/chapters/sign-in-sign-out#top but i don't want it on an extra page.
so I tried setting the routes and I got an exception "no path found for '/'" as soon as I deleted "resources :sessions" it worked fine again.
my partial looks like this:
<%= form_for(User.new) do |f| %>
<%= f.submit "Login" %>
<% end %>
there's also a div class="action" block around the submit but can't find out how to escape it
this is included into my home via
<%= render 'sessions/new' %>
Thanks for your help
edit my solution:
I added to routes.rb:
resources :sessions
Furthermore I changed form_for(#user) to
<%= form_for(:session, url => sessions_path)
so this works.
I Highly recommed that you look at the railscast http://railscasts.com/episodes/250-authentication-from-scratch , it will give you an idea how to create authentication without forgetting some important steps.
Then you can use the gem devise which is an excellent authentication gem.
Have you tried putting your functions and everything for authentication within a Session Helpers file? Then, in your Application Controller if you add "include SessionsHelper" this should give you access to all the helper functions from Session that you should need

Devise: NoMethod Error & user_signed_in

I'm trying to use user_signed_in? to add a login area to my rails 3 application using devise 1.1.3 and I get a NoMethodErrorin Rules#index
<% if user_signed_in? -%>
<div id="user_login_box" style="float:right">
<%= current_user.email %> |
<%= link_to 'My info', edit_user_registration_path %> |
<%= link_to 'Sign out', destroy_user_session_path %>
</div>
<% end -%>
I'm not sure what's wrong exactly, but clearly the devise method isn't being used. I'm also fairly (read: really) new to rails and haven't used devise before.
What is the name of the model you generated Devise for?
If you called it something else instead of User, you might want to check out http://groups.google.com/group/plataformatec-devise/msg/67f1eb5a571b6136
I had the exactly the same issue.
undefined local variable or method 'edit_user_registration_path'
However, I have devise :database_authenticatable, but not :registerable. After I added the :registerable everything works!
You seem to be missing the call to devise :database_authenticatable in your User model.
Also, a good way to get started with devise is to look at the excellent RailsCasts by Ryan Bates : Introducing Devise.
It also may happen that your trying to call that route from another engine, so in that case you have to specify the context for that route, like main_app.edit_user_registration_path.

Rails 3 :method=> :delete doesn't work in Internet Explorer

I am going through the rails 3 tutorial at railstutorial.org. I have just created an extremely simple scaffold Users.
The scaffold-generated destroy link does not work in Internet Explorer. It redirects to the show action instead of deleting the user.
This problem only happens in IE9 and IE8 (the only IE versions I've tested so far) The problem DOES NOT happen in Firefox. Can anyone tell me why this is happening?
The view:
<%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %>
Generated HTML:
Destroy
The controller:
def destroy
#user = User.find(params[:id])
#user.destroy
respond_to do |format|
format.html { redirect_to(users_url) }
format.xml { head :ok }
end
end
In Rails 3.1 with the asset pipeline, all the javascript is in application.js. So, rather than :defaults, you need "application".
<%= javascript_include_tag "application" %>
Make sure you have <%= javascript_include_tag :defaults %>
JS is now unobtrusive in rails 3, so the include is required to make it work.
Replace public/javascripts/rails.js of your application with this one:
https://github.com/rails/prototype-ujs/raw/master/src/rails.js
This is updated recently (2010/11/13).
The rails.js bundled with Rails 3.0.0/3.0.1 does not work well on Internet Explorer.
You need to upgrade your prototype distribution to 1.7 instead of 1.7rc2 (which doesn't have full support for IE 9). The latest Rails gem (at time of writing( in the gem repo is bundling 1.7rc2. Go to the prototype homepage, download the new 1.7 release and replace this with the bundled prototype.js.
I couldn't get it to work with IE9 with the default javascript libraries, so I installed jquery-rails and it works just fine. Not perhaps the ideal solution, but if it works...
By default, new rails projects are created with Prototype javascript libraries, with some prototype-specific helper functions in "public/javascript/rails.js". The scaffolding relies on some of these helpers to handle some things, like destroying a record, since there isn't a good javascript-free way of making a DELETE request, etc.
Make sure that your pages are loading both the javascript libraries and the "rails.js" file, which are needed to make the scaffolding work (see theschmitzer's answer, or check in Firebug).
Second, if you are using jQuery, install the 'jquery-rails' gem and then run "rails g jquery:install". This will remove the Prototype libraries, install the jQuery libraries, and update the helpers to use jQuery.
Try replacing your javascript default include with:
<%= javascript_include_tag "jquery" %>
<%= javascript_include_tag "jquery.min" %>
<%= javascript_include_tag "rails" %>
after following the steps above to get the latest jquery.js, jquery.min.js, and rails.js. That worked for me, anyway.
Or, replace the meaning of :defaults in application.rb:
config.action_view.javascript_expansions[:defaults] = %w(jquery jquery.min rails)
And then your application layout can still look have
<%= javascript_include_tag :defaults %>
This is probably because the loading of your script (rails.js and/or application.js) happens in head. At script execution time, there are no elements in your DOM with the attributes data-confirm and data-method.
So, the solution is to move the javascript tag to the end of <body>. At this time, the DOM has most likely been loaded and the javascript will find your elements.
I experience the same problem, regardless of web browser.
theschmitzer's answer didn't help me.
I found that as long as I am using the jquery javascript library the destroy method in the controller is never called.
In my case I had a conflict between the javascript libraries (jQuery and Prototype) which was hard to figure out for such a newbie. I changed completely to jQuery - as in the end of this railcast: http://railscasts.com/episodes/205-unobtrusive-javascript
I had the same problem. I was using the <%= javascript_include_tag :defaults %> as well as the jQuery library. When I removed the jQuery library, things worked. Also, you could use noConflict().
I notice that in rails 4, link_to puts the :method as a html attribute "data-method" but :confirm goes to an attribute "confirm" where the javascript needs it to be "data-confirm".
Not sure if this is a bug in rails, but you can work around it by doing this:
<%= link_to 'Destroy', user, :data => {:confirm => 'Are you sure?'}, :method => :delete %>