simple rails login system

Hey All,

    Just started to play around with rails a bit today by creating a
login system, but I've run into a glitch.


class UserController < ApplicationController

def login
        @title = "Log In"
        if and params[:user]
                @user =[:user])
                @userfind =

                if @userfind

                        redirect_to :action => "index"

                        render :text => "Login Failed"

  def index

          db = Mysql.connect('localhost','root','godsp33d','netv_dev')
        feed_url = db.query("SELECT feeds FROM users WHERE username =
'#{@user.username}' AND password = '#{@user.password}'")

        feed_url.each do |x|
                x.each do |b|
                        @feeds = b.split(",")
@feeds.each do |links|
        open(links) do |http|
                response =
                result = RSS::Parser.parse(response, false)
                result.items.each_with_index do |item, i|
                        output += "#{i + 1}. <a
href=\"#{}\">#{item.title}</a> <br />"
# output += "============================================"



  def register

          @title = "Register"
                  @user =[:user])
                          render :text => "Account Created."


Hmm..not sure what the problem with the code is...if you're interested
in a fast login system, you can try the acts_as_authenticated plugin.

Just type sudo ruby script/plugin install

Then in your application.rb file, you can just type:
include AuthenticatedSystem and before_filter :login_from_cookie

With it installed, you get some scripts to generate things. So:
ruby script/generate authenticated user account

gives you some migrations and some views to play around with.

On the other hand, if you want to build it homegrown, I totally


You can then put before_filter :login_required before any controller
you want password protected.

Ron wrote:

On the other hand, if you want to build it homegrown, I totally

Yeah, I saw and checked out a few things revolving around those
generators, but I'm more out for knowledge than a quick solution that I
would have no general idea on how it works.

Thanks a lot for the info though!

- Mac