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}</a> <br />"
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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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 http://svn.techno-weenie.net/projects/plugins/acts_as_authenticated/ 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 understand. Ron You can then put before_filter :login_required before any controller you want password protected. On Jun 15, 8:17 pm, Michael Linfield <rails-mailing-l...@andreas- s.net> wrote:> 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}</a> <br />" > 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 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ron wrote:> On the other hand, if you want to build it homegrown, I totally > understand.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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---