Hey All,
Just started to play around with rails a bit today by creating a
login system, but I’ve run into a glitch.
###user_controller.rb###
class UserController < ApplicationController
def login
@title = “Log In”
if request.post? and params[:user]
@user = User.new(params[:user])
@userfind =
User.find_by_username_and_password(@user.username,@user.password)
if @userfind
redirect_to :action => "index"
else
render :text => "Login Failed"
end
end
end
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(",")
end
end
@feeds.each do |links|
open(links) do |http|
response = http.read
result = RSS::Parser.parse(response, false)
result.items.each_with_index do |item, i|
output += “#{i + 1}. <a
href=”#{item.link}">#{item.title}
"
end
output += “============================================”
end
end
end
def register
@title = "Register"
if request.post?
@user = User.new(params[:user])
if @user.save
render :text => "Account Created."
end
end
end
end
user_model.rb
class User < ActiveRecord::Base
end
Basically the problem occurs in ‘index’, @user keeps returning nil only
in index (works fine in register) when pushed through the sql query it
returns nil. Is there a proper method to extracting the entered
information via html form to push it through an SQL query?
My apologies for the formatting, Copied the text while working in
fullscreen.
Thanks for any suggestions you can throw my way,
- Mac