Confused about 'respond_to' vs 'respond_to?'

后端 未结 3 794
别那么骄傲
别那么骄傲 2021-01-30 02:09

I am learning Rails with railstutorial.org, and I am confused about something: in this chapter the author tells us to do some testing in the console with the respond_to?

3条回答
  •  天命终不由人
    2021-01-30 02:41

    The test uses convenient helpers to be more user friendly.

    Ruby is Ruby so using the good old respond_to? would work if you call it this way:

     @user.respond_to?(:encrypted_password).should be_true
    

    There is another respond_to used in controllers but still nothing to do with those you already met.

提交回复
热议问题