Topic: Case statement

    def set_flash_message(page)
      if page.permalink.first(4) == "clix"
        "PPC Page has been successfully deleted."
      else
        case page.permalink
          when "discount"           then "Discount Page has been successfully deleted."
          when "affiliate_program"  then "Affiliate Page has been successfully deleted."
          else                      "Page has been successfully deleted."
        end
      end
    end

I have permalink values as "clix1.html", "clix2.html" ....."clix10.html"

How can make the values in the case statement.

Please do let me know your thoughts!

Thank you for your time!

Re: Case statement

Aren't you already doing that?

Can you explain more about what you want to do, ie the requirements, here?  "How can make the values in the case statement."  isn't enough i'm afraid.

###########################################
#If i've helped you then please recommend me at Working With Rails:
#http://www.workingwithrails.com/person/ … i-williams

Re: Case statement

Your current code contains a lot of duplication. Also, it's brittle - every time you add or change a page, you have to change this too. Suppose you adopted a standard page naming convention, then you could do something like:

permalinks = %w{discount affiliate ppc1.html ppc10.html}

permalinks.each do |permalink|
  page = permalink.scan(/^[A-Za-z]+/)[0] || ''
  p "#{page.capitalize} page has been successfully deleted"
end

Provided you stick to sensible names for your permalinks, you'd never have to touch it again...