Last active
August 29, 2015 14:06
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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