pakyow-presenter/lib/presenter/binder_set.rb in pakyow-presenter-0.9.1 vs pakyow-presenter/lib/presenter/binder_set.rb in pakyow-presenter-0.10.0

- old
+ new

@@ -65,29 +65,33 @@ @options[name] = block @config[name] = { empty: empty } end def restful(route_group) - binding(:action) { + binding :_root do routes = Router.instance.group(route_group) - return_data = {} - if id = bindable[:id] - return_data[:view] = lambda { |view| - view.prepend(View.new('<input type="hidden" name="_method" value="patch">')) - } + { + view: lambda { |view| + action = view.attrs.action.value + return if (action && !action.empty?) - action = routes.path(:update, :"#{route_group}_id" => id) - else - action = routes.path(:create) - end + route_params = params.dup + if view.doc.tagname == 'form' + if id = bindable[:id] + view.prepend(View.new('<input type="hidden" name="_method" value="patch">')) + route_params[:"#{route_group}_id"] = id + action = :update + else + action = :create + end - return_data[:action] = action - return_data[:method] = 'post' - return_data - } + view.attrs.action = routes.path(action, route_params) + view.attrs.method = 'post' + end + } + } + end end - - #TODO options end end end