Skip to content

Instantly share code, notes, and snippets.

@joshrendek
Created January 4, 2011 15:03
Show Gist options
  • Save joshrendek/764866 to your computer and use it in GitHub Desktop.
Save joshrendek/764866 to your computer and use it in GitHub Desktop.
<%= form_for(@comment, @code) do |f| %>
<%= f.hidden_field :commentable, :value => commentable.class.name %>
<%= f.hidden_field :commentable_id, :value => commentable.id %>
<%= f.label :content %><br />
<%= f.text_area :content %><br />
<%= f.fields_for @code do |c| %>
<div class="field">
<%= c.select "file_type", SourceCode::FILE_TYPES %>
<%= c.label :source %><br />
<%= c.text_area :source %>
</div>
<% end %>
<%= f.submit %>
<% end %>
<%= render :partial => 'comments/form', :locals => {:commentable => @question} %>
# part of the controller to determine class
c = params[:comment]
@commentable = nil
if c[:commentable]== "Question"
@commentable = Question.find(c[:commentable_id])
elsif c[:commentable] == "Snippet"
@commentable = Snippet.find(c[:commentable_id])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment