ChrisGeek
ChrisGeek

Reputation: 67

Hash Param[:id] before_Action

I have a route,the value of the id is encrypted,which means it has to be decrypted before the action is called,my question is how do i get the id,decrypt it and set the new one to the route using a before_action filter,below is what i have tried controller:

before_action :reverse_id, only: :public_download

def reverse_id 
  @swapped_id = params[:id]
  @id = ScatterSwap.reverse_hash(@swapped_id).to_i
  params[:id] = @id

end

def public_download
  //do something
end

this is my route

get "get_score/:id/", to: "controller_name#public_download", as:       :get_score

Upvotes: 0

Views: 107

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230461

This code doesn't work. I get the same id i put into the url rather than the decrypted value

Fortunately for you, you don't have to mutate params at all. Why not simply replace MyModel.find(params[:id]) with MyModel.find(decrypt(params[:id]))? (where decrypt method does only that, decryption)

Upvotes: 1

Related Questions