Forum: Ruby on Rails two things seem to equal, but the UNLESS statement passes anyway.

Posted by Binny Zupnick (bzupnick)
on 2012-12-20 11:47
Attachment: code.txt (569 Bytes)
when params[:which_post] happens to equal the users last message, the
UNLESS staement on line 11 passes when in fact they both equal. I've
done testing and I know the params work and they do in fact equal each
other, but it still passes when it shouldn't.
Posted by Jim ruther Nill (jimboker)
on 2012-12-20 11:59
(Received via mailing list)
On Thu, Dec 20, 2012 at 6:47 PM, Binny Zupnick <lists@ruby-forum.com> 
wrote:

> when params[:which_post] happens to equal the users last message, the
> UNLESS staement on line 11 passes when in fact they both equal. I've
> done testing and I know the params work and they do in fact equal each
> other, but it still passes when it shouldn't.
>

nothing that is passed as a params will be typecasted as an integer so 
you
may need
to apply a .to_s to @message.id or .to_i to params[:which_post]


> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>


--
Posted by Jim ruther Nill (jimboker)
on 2012-12-20 12:02
(Received via mailing list)
On Thu, Dec 20, 2012 at 6:58 PM, Jim Ruther Nill <jvnill@gmail.com> 
wrote:

>
> nothing that is passed as a params will be typecasted as an integer so you
> may need
> to apply a .to_s to @message.id or .to_i to params[:which_post]
>

just a follow up, it is better to assign the records to an instance
variable in the controller.
something like

# setup which_post here
@messages = @user.messages.where('messages.id != ?', which_post)

and then just use @messages on the view


>> --
>
> --
> -------------------------------------------------------------
> visit my blog at http://jimlabs.heroku.com
>



--
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.