I'm a newbie Rails learner. I want to try out some ruby language features, e.g. shorten the following method:
def update(params)
attrs = []
params[:attributes].each do |attr_hash|
attr = Attribute.new attr_hash
attrs.push attr
end
...
end
like:
def update(params)
attrs = fill_attrs_from_params params
...
end
def fill_attrs_from_params(params)
attrs = params[:attributes].each do |attr_hash|
Attribute.new(attr_hash)
end
end
The second doesn't work as the first one however. What do I miss here?
Edit: I couldn't really decide how the second one worked, the application went buggy, and I'm a beginner with rails debugging as well.
attrsonfill_attrs_from_paramsyou could just iterate overparams[:attributes].Enumerable#map.Enumerable#map, actually :)