13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/action_controller_extensions/action_controller_class_methods.rb', line 13
def resource_attributes(*parameters)
for action in [:show, :new, :edit, :create]
a = "def #{action};" + ([:new, :create].include?(action) ?
"@#{resource_class.name.underscore} = resource_class.new;" : ""
) +
parameters.map{|p|
if p.class == Hash
meth, prm = [p.to_a.flatten[0], p.to_a.flatten[1]]
else
meth, prm = [p, p]
end
meth = meth.to_s + "="
if prm == :current_user
val = "current_user"
else
val = "params[:#{prm}]"
end
"resource.send(\"#{meth}\", #{val})"
}.join(";") +
";#{action}!;end;"
class_eval a
puts a
end
end
|