Controllers Should Convert Parameters to Richer Types
Understand how to handle parameter conversion in Rails controllers by transforming string inputs from HTTP into appropriate types. Learn why controllers shield the business logic from raw strings and how to manage type conversions effectively, balancing Active Record conveniences with custom needs.
We'll cover the following...
We'll cover the following...
Active Record handling
As the invokers of business logic, controllers are responsible for converting parameters into properly typed objects:
def show
@widget = Widget.find(params[:id])
end
This code takes a string containing an identifier that we assume identifies a widget and looks it up ...