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
<%= form_for @project do |f| %> | |
<% if @project.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(@project.errors.count, "error") %> prohibited | |
this project from being saved:</h2> | |
<ul> | |
<% @project.errors.full_messages.each do |msg| %> | |
<li><%= msg %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<table class="FormTable"> | |
<tr> | |
<th class="TitleRow" colspan="2"><%= @formTitle %></th> | |
</tr> | |
<tr> | |
<td> </td> | |
<td class="labeldesc"> </td> | |
</tr> | |
<tr> | |
<td class="label">Project Title:</td> | |
<td class="data"><%= f.text_field :title %></td> | |
</tr> | |
<tr> | |
<td> </td> | |
<td class="labeldesc"> </td> | |
</tr> | |
<tr> | |
<td class="label">Funding Source:</td> | |
<td class="data"><%= f.collection_select :funding_source, FundingSource.all, :description, :description, :prompt => 'Please select a funding source' %></td> | |
</tr> | |
<tr> | |
<td> </td> | |
<td class="labeldesc"> </td> | |
</tr> | |
<tr> | |
<td> </td> | |
<td class="labeldesc">A brief description of the project and its potential significance.</td> | |
</tr> | |
<tr> | |
<td class="label">Executive Summary:</td> | |
<td class="data"><%= f.text_area :executive_summary %></td> | |
</tr> | |
<% if @formMode == "new" then %> | |
<tr> | |
<td> </td> | |
<td class="labeldesc" colspan="2">List of deliverables (e.g. algorithm, process, tool, service, etc)</td> | |
</tr> | |
<tr> | |
<td class="label">Primary Deliverables:</td> | |
<td class="data"> | |
<%= f.fields_for :deliverables do |deliverable_field| %> | |
<%= render 'deliverables/deliverable_fields', :f => deliverable_field %> | |
<% end %> | |
</td> | |
</tr> | |
<tr> | |
<td> </td> | |
<td class="addlink"><%= link_to_add_fields "Add More", f, :deliverables %></td> | |
<% if false then %> <td class="addlink"><a href="">Add More</a></td> <% end %> | |
</tr> | |
<% end %> | |
<% if @formMode == "new" then %> | |
<%= f.fields_for :images do |image_field| %> | |
<%= render 'images/image_fields', :f => image_field %> | |
<% end %> | |
<% end %> | |
<tr> | |
<td colspan="2"> </td> | |
</tr> | |
<tr class="BottomButtonRow"> | |
<td colspan="2"> | |
<table> | |
<tr> | |
<td class="left"> | |
<%= link_to 'Cancel', @project %> | |
</td> | |
<td class="right"> | |
<input name="" type="submit" value="Save" /> | |
</td> | |
</tr> | |
</table> | |
</td> | |
</tr> | |
</table> | |
<% end %> | |
<% if @formMode == "new" then %> | |
<script> | |
$(function() { | |
$('#project_images_attributes_0_url').change(function(){ | |
$('#thumbnail').attr("src", $(this).val()); | |
// alert("test"); | |
}); | |
}); | |
</script> | |
<% end %> |
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
$('a.add-fields').on('click', function() { | |
var association = $(this).attr('data-association'), | |
fields = $(this).attr('data-fields'), | |
new_id = new Date().getTime(), | |
regexp = new RegExp("new_" + association, "g") | |
$(link).parent().before(content.replace(regexp, new_id)); | |
}); |
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
module ApplicationHelper | |
def link_to_add_fields(name, f, association) | |
new_object = f.object.class.reflect_on_association(association).klass.new | |
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| | |
render(association.to_s.pluralize + "/" + association.to_s.singularize + "_fields", :f => builder) | |
end | |
link_to name, '#', class: 'add-fields', data: { association: association, fields: escape_javascript(fields) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment