Hello i know this is common problem but i cant let it work.. I need account activation from email link.. url looks like http://domain.tld/activation/[email protected]/d4sa89dsa98 and i want access that parameters from controller :-)
routes.rb
match "activation/:email/:activation_key" => "frontend#activation", :via => :get
frontend_controller.rb
def activation
@user = User.find(:conditions => {:email => params[:email], activation_key => params[:activation_key]})
render "activation"
end
and im getting error
No route matches [GET] "/activation/[email protected]/a46d4sa8dsa68d"
my activation.html.erb
<% if @user %>
Activation successful.
<% else %>
Activation key is invalid.
<% end %>
EDIT: ---------------------------------------------------------------------------------------------------------------------------
I replaced :email parameter with :id parameter because it look nicer, im not sure if
Array.new(32){Random.new.rand(36).to_s(36)}.join is unique string but that does not matter now.
route
match "activation/:id/:activation_key" => "frontend#activation", :via => :get
rake routes
GET /activation/:id/:activation_key(.:format) frontend#activation
frontend controller
def activation
@user = User.find(:conditions => {:id => params[:id], :activation_key => params[:activation_key]})
render "activation"
end
error
Couldn't find User without an ID
but this WORKS so the problem is in the condition
@user = User.find(params[:id])
SOLUTION
@user = User.find(:first, :conditions => {:id => params[:id], :activation_key => params[:activation_key]})
SecureRandom.uuid.. i changed :email to :id but now it saysCouldn't find User without an IDthat meansparams[:id]doesnt work.. i will edit question for more information