Rails: Duplicate functionality across controllers? A humble plea.

Posted by Alex on Stack Overflow See other posts from Stack Overflow or by Alex
Published on 2010-05-19T03:47:57Z Indexed on 2010/05/19 3:50 UTC
Read the original article Hit count: 169

Filed under:

So I'm working with authlogic, and I'm trying to duplicate the login functionality to the welcome page, so that you can log in by restful url or by just going to the main page. No, I don't know if we'll keep that feature, but I want to test it out anyway. Here's the error message:

RuntimeError in Welcome#index Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

The code is below. Basically, what's happening is the index view (the first code snippet) is sending the information from the form to the create method of user_sessions controller. At this point, in theory, it create should just pick up, but it doesn't.

PLEASE help. Please. I've been doing this for about 8 hours. I checked Google. I checked IRC. I checked every book I could find. You don't even have to answer, I can to the grunt work if you just point me in the right direction.

<% form_for @user_session, :url => user_sessions_path do |f| %>
    <%= f.text_field :email %><br />
    <%= f.password_field :password %>
    <%= submit_tag 'Login' %>
<% end %>

class ApplicationController < ActionController::Base helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryProtection for details # Scrub sensitive parameters from your log # filter_parameter_logging :password helper_method :current_user_session, :current_user before_filter :new_session_object protected def new_session_object unless current_user @user_session = UserSession.new(params[:user_session]) end end private def current_user_session return @current_user_session if defined?(@current_user_session) @current_user_session = UserSession.find end def current_user return @current_user if defined?(@current_user) @current_user = current_user_session && current_user_session.record end end

© Stack Overflow or respective owner

Related posts about ruby-on-rails