Skip to content

Instantly share code, notes, and snippets.

@ffaerber
Last active August 29, 2015 14:06
Show Gist options
  • Save ffaerber/6577e082baf7f54e1b3d to your computer and use it in GitHub Desktop.
Save ffaerber/6577e082baf7f54e1b3d to your computer and use it in GitHub Desktop.
simple_form submit modal with remote:true against inherited_resources and working form validation in rails.
.modal-dialog
.modal-content
.modal-header
%button.close{"aria-hidden" => "true", "data-dismiss" => "modal", type: "button"} ×
%h4.modal-title= t'new_node'
.modal-body
= simple_form_for @node, remote: true do |f|
- value = params[:environment_id].nil? ? {} : { value: params[:environment_id] }
= f.input :environment_id, as: :hidden, input_html: {}.merge(value)
= render 'nodes/form_fields', f: f
= f.button :submit, id: 'submit', class: 'btn btn-success'
class NodesController < InheritedResources::Base
respond_to :html, :json, :js
...
def update
update! do |success, failure|
@node = NodeDecorator.new(@node)
success.js { @node }
failure.js { render :edit }
end
end
def create
create! do |success, failure|
@node = NodeDecorator.new(@node)
success.js { @node }
failure.js { render :new }
end
end
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment