Search code examples
rubyweb-applicationscamping

Sanitise user input in Camping


In Camping, how do I sanitise user input?

@input.user

Solution

  • What do you mean by "sanitise"?

    If you're using ActiveRecord to insert/query data, sanitising should be handled for you:

    class UserX
      def get
        @user = User.where(:name => @input.name).first
      end
    end
    

    If you're thinking about HTML sanitising, Markaby should handle it for you:

    def user
      h1 @input.name     # This is automatically escaped
      h1 { @input.name } # This is not escaped
    end