Skip to content

Instantly share code, notes, and snippets.

@tubbo
Forked from anonymous/_form.html.erb
Last active August 29, 2015 13:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tubbo/9606912 to your computer and use it in GitHub Desktop.
<%= 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>&nbsp;</td>
<td class="labeldesc">&nbsp;</td>
</tr>
<tr>
<td class="label">Project Title:</td>
<td class="data"><%= f.text_field :title %></td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="labeldesc">&nbsp;</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>&nbsp;</td>
<td class="labeldesc">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</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>&nbsp;</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>&nbsp;</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">&nbsp;</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 %>
$('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));
});
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