Hello! I have database called "Auth", there are following fields: id, auth, is_active, created_at, updated_at and i have 1 active record: ------------------------------------------------------------------------------------ 1, lala999, 1, 20-03-20111 15:14:12, 20-03-20111 15:14:12 ------------------------------------------------------------------------------------ I need following url => `''localhost:3000/?auth=lala9999''` (this I have in my database and this field should come from DB). How can i do it? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 29 March 2011 08:22, HelloRails <vitalizakharoff-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello! > > I have database called "Auth", there are following fields: id, auth, > is_active, created_at, updated_at and i have 1 active record: > ------------------------------------------------------------------------------------ > 1, lala999, 1, 20-03-20111 15:14:12, 20-03-20111 15:14:12 > ------------------------------------------------------------------------------------ > > I need following url => `''localhost:3000/?auth=lala9999''` (this I have > in my database and this field should come from DB). > > How can i do it?One way to slice it: In your controller''s find action, instead of doing: @auth = Auth.find(params[:id]) You could use: @auth = Auth.find_by_auth(params[:auth]) I''m assuming you have a unique constraint on the auth field... -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for fast response!.
#controller
class AnswersController < ApplicationController
layout "default"
def create
@w1 = rand(9999999)
@w = Digest::SHA1.hexdigest(@w1.to_s)
@token = Token.find_by_token(params[:token])
# params[:token]
@answers=Hash.new
# if request.post?
#@answers = Answer.new(:token=>121,:question_id=>question.id)
questions = Question.find(:all,:conditions=>"enabled=1")
questions.each do |question|
if params["answer_"+question.id.to_s]
@answers[question.id]=params["answer_"+question.id.to_s]
if !
Answer.create(:question_id=>question.id,:token=>"",:text=>params["answer_"+question.id.to_s])
flash[:error]="Can`t create answer!"
end
end
end
if !flash[:error]
redirect_to :action=>"pass"
return false
end
# end
end
def index
@answers=Hash.new
@questions = Question.find(:all,:conditions=>"enabled=1")
#.where(["id = 1"])
end
def pass
flash[:notice]="<span id=''ty''>Thank you for your
answers!</span>"
render :text=>"", :layout=>"ty"
end
def about
end
end
#############
How i can check tokens?
if @token (from db) == token_url (check the url) ?
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 29, 8:39 am, HelloRails <vitalizakhar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ############# > How i can check tokens? > if @token (from db) == token_url (check the url) ?Well I''m entirely sure what you''re trying to do but presumably you''ll need to grab something out of the params hash (params[:auth] for the url given in your first email) and then verify that a token of that value does indeed exist in your database (and is still active) Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.