Home>
How to separate methods
card = Card.find_by (user_id: current_user.id) is also used in other actions, so I was told to divide it into methods, but I don't know how to do it.
Please professor
class PurchaseController 10000,
: customer =>card.customer_id,
: currency =>'jpy',
)
redirect_to action: 'done'
end
def done
card = current_user.cards.first
redirect_to controller: "card", action: "new" if card.blank?
end
end
-
Answer # 1
Related articles
- ruby - i want to know the reason for implementing it in a class method or module when solving an exercise
- ruby on rails - i want to use yield in a method chain
- ruby - no method error rails
- ruby - i'm using the errors method, but i don't get an error message
- ruby on rails: undefined method ʻuser'for nil: about nomethoderror of nilclass
- ruby - undefined method `save'for nil: nilclass cannot be resolved
- ruby - improvement of nomethoderror undefined method `paginate'
- [ruby] "attr_accessor" i don't understand this method
- ruby on rails - [rails] i want to make it a helper method
- ruby - nomethoderror: undefined method `new'for: uglifier: symbol error on heroku deployment
- ruby on rails - [rails] i want to use each statement in a helper method
- the ruby on rails each method does not repeat well
- ruby - where method doesn't work
- ruby - the method defined in the model cannot be used
- ruby - undefined method `build_address' for order (table doesn't exist): class send data to db
- ruby on rails5 nomethoderror (undefined method `cart_items' for nil:nilclass) implementation of ec site cart function
- ruby - cannot save data by save method
- about ruby count method
- ruby on rails 6 - i want to resolve undefined method `[]' for nil:nilclass
- ruby undefined method `find_zone!' for time:class (nomethoderror) error
Related questions
- ruby - passing variables using render partial
- ruby - #i want to see a list of posts for that user on the user details page
- ruby - implementation of friendly forwarding
- ruby - i installed carrierwave with rails, but i can't see the image
- ruby - about rails controller new action
- ruby - rails page does not open
- [ruby] i'm having trouble with nomethoderror
- ruby - [search function] acquisition of products associated with users
- ruby - even if each statement is used, the contents of the db cannot be displayed in order and an error occurs
- ruby - if i include the'omniauth-facebook'gem, do i need to install the'omniauth' gem as well?
I wonder if it is necessary to cut out such a short, but if you dare do it
before_action: set_card, only: Write [: index,: pay]
at the beginning