SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with controller logic

    Hello,

    This is a method that I have written to show personal messages. If the message that is requested is sent "to" the logged in user I will do another check and set status to opened if necessary. I can't figure out why the last "else" statement never executes if the first one is false: Message.find(params[:id], :conditions => {:from )


    Code Ruby:
        def show
        if @message = Message.find(params[:id], :conditions => {:to => @user.id }) then
         if @message.status = "new"
         	@message.status = "opened"
            @message.save
          end    
    	else 
    		@message = Message.find(params[:id], :conditions => {:from => @user.id })
        end
    	rescue ActiveRecord::RecordNotFound
      end

  2. #2
    l 0 l silver trophybronze trophy lo0ol's Avatar
    Join Date
    Aug 2002
    Location
    Palo Alto
    Posts
    5,329
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You're assigning 'new' to the status:

    Code Ruby:
    if @message.status = "new"

    Use the comparison operator instead.

    Code Ruby:
    if @message.status == "new"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •