I'm creating a web application, but I'm worried about how to design the return value of the module.
Consider creating a simple module called Update user_name in the users model
moduleUserNameUpdate
default(user,user_name)
if user.blank?
return xxx
end
if user_name.blank?
return xxx
end
US>user.update!(user_name:user_name)
end
end
The argument is not nil, and if necessary, we may also check the type.
I thought about returning it with hash and string, but I would like to read a deep and instructive document.
moduleUserNameUpdate
default(user,user_name)
hash = {
code: 1,
message:nil
}
if user.blank?
hash ['message'] = 'message for argument is nil'
return hash
end
if user_name.blank?
hash ['message'] = 'user_name in argument is nil'
return hash
end
US>user.update!(user_name:user_name)
end
end
What is the best way to design the return value?I think it is a universal issue regardless of Ruby/Rails, so language/FW is not particularly limited.
Please let me know if you have any documents or good ideas.
Also, what should I put on the tag?I don't have that kind of tag.
ruby-on-rails programming-language detailed-design
As @shingo.nakanishi said, the appropriate design will change depending on the language and FW (functionality provided by ).Perhaps the final questioner would like to know is what is the right (sure) way to implement this feature in rails.
Based on this assumption, the column value check is almost done this time, so I think it is a rails-like implementation to follow the active record validation found in rail tutorial.
Here's an excerpt. If it's a value check for a column,
class Person <ActiveRecord::Base
values:name, presence:true
end
It can be written declaratively as shown in .
© 2024 OneMinuteCode. All rights reserved.