Reputation: 2643
I'm creating a newsletter.
Each email contains a link for editing your subscription:
<%= edit_user_url(@user, :secret => @user.created_at.to_i) %>
:secret => @user.created_at.to_i prevents users from editing each others profiles.
def edit
@user = user.find(params[:id])
if params[:secret] == @user.created_at.to_i
render 'edit'
else
redirect_to root_path
end
end
It doesn't work - you're always redirected to root_path.
It works if I modify it like this:
def edit
@user = user.find(params[:id])
if params[:secret] == "1293894219"
...
1293894219 is the "created_at.to_i" for a particular user.
Do you have any ideas why?
Upvotes: 0
Views: 1191
Reputation: 14268
if params[:secret] == @user.created_at.to_i.to_s
The parameter is a string not an integer.
Upvotes: 2