Skip to content

Instantly share code, notes, and snippets.

@twinge
Created October 8, 2010 18:01
Show Gist options
  • Save twinge/617227 to your computer and use it in GitHub Desktop.
Save twinge/617227 to your computer and use it in GitHub Desktop.
## _form.html.erb ##
<%= link_to(image_tag(element.element_data.url(:thumb)), portfolio_add_element_path(element), :remote=>true) %>
## Portfolios_Controller.rb ##
respond_to :js, :html
def add_element
@portfolio = Portfolio.find(portfolio_id)
@element = Element.find(element_id)
@portfolio.elements.create(@element)
respond_with(@portfolio) do |format|
# You don't want to redirect when you come from an ajax call.
format.html { redirect_to (@portfolio) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment