rails comparing values of params[:id] and session[:user_id] not working

pedalpete picture pedalpete · Jul 19, 2010 · Viewed 30.9k times · Source

I'm new to rails after moving from PHP and am having no end to the frustrations, but hopefully there is a steep learning curve.

I was following a guide on how to make a twitter clone in rails, and have continued along that path making it more and more twitter like.

So I've got a 'users' page /users/show.html.erb which show all the posts from a user.

Now, if the currently logged in user is the same as the page owner, I'm trying to show the text box so that the user can add a new entry.

I've got what should be a very simple

<% if params[:id] == session[:user_id] %>
    put the text box here
<% end %>

of course, that isn't working, but right above it I've output both the session[:user_id] and the params[:id], and the printout is exactly the same.

If I set the == to !=, I get the 'put the text box here' message.

any suggestions as to what I'm doing wrong? I know these two values match, as I can see in the url and the output of the currently logged-in user. I've also output

-<% session[:user_id] %>-
-<% params[:id] %>-

so that I can see there is no gaps or spaces or other characters on either end of the parameters, and it all looks clean.

The output looks like this

-4c4483ae15a7900fcc000003-
-4c4483ae15a7900fcc000003- 

which is the mongodb objectId of the user with dashes on either side to show that there are no spaces or anything.

Answer

jasonpgignac picture jasonpgignac · Jul 19, 2010

Are you sure that both items are simple strings? What happens if you run, say

params[:id].to_s == session[:user_id].to_s

?