Created
September 23, 2014 14:26
-
-
Save mdunbavan/19c4488d653fe301eb9c to your computer and use it in GitHub Desktop.
ajax submit
This file contains hidden or 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
| // Inside books/form | |
| <%= simple_form_for(@book, :remote => true, :authenticity_token => true, :html => { :multipart => true }) do |f| %> | |
| <%= f.error_notification %> | |
| <div class="inputs"> | |
| <%= f.file_field :jacket_cover %> | |
| <%= f.input :title %> | |
| <%= f.input :synopsis, :as => :ckeditor, :label => false, :input_html => { :ckeditor => { :toolbar => 'Full', :height => 400 } } %> | |
| <%= f.input :body, :as => :ckeditor, :label => false, :input_html => { :ckeditor => { :toolbar => 'Full', :height => 400 } } %> | |
| <%= f.input :age, collection: 0..100, prompt: "Select age range" %> | |
| <%= f.input :publisher %> | |
| </div> | |
| <h4>Select cuurent authors if applicable: </h4> | |
| <%= f.select( :author_id, Author.all.map {|u| [u.name,u.id]}, {:include_blank => false, prompt: "No Author"} ) %> | |
| <div id="author-inputs" style="display: none !important;"> | |
| <h4>If you cannot see the author above create one here! </h4> | |
| <%= render :partial => 'authors/form', :object => @author %> | |
| </div> | |
| <!-- Important bit here --> | |
| <%= link_to 'New Author', new_author_path, :remote => true, :id => "new_author_link" %> | |
| <div id="authors"></div> | |
| <div class="actions"> | |
| <%= f.button :submit %> | |
| </div> | |
| <% end %> |
This file contains hidden or 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
| // In authors/form | |
| <% if @author.errors.count == 0 %> | |
| $('#new_author').remove(); | |
| $('#new_author_link').show(); | |
| $('#authors-added h3').html('Author sucessfully added'); | |
| $('#authors').append('<%= j render("author", :author => @author) %>'); | |
| <% else %> | |
| $('.new_author').remove(); | |
| $('#new_author_link').after('<%= j render("form") %>'); | |
| <% end %> |
This file contains hidden or 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
| // In authors/form | |
| $('#new_author_link').hide().after('<%= j render("form") %>'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment