Link + Params

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

On 29 March 2011 08:22, HelloRails [email protected] wrote:

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…

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]=“Thank you for your answers!
render :text=>"", :layout=>“ty”
end

def about
end

end

#############
How i can check tokens?
if @token (from db) == token_url (check the url) ?

On Mar 29, 8:39am, HelloRails [email protected] 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