Last active
August 29, 2015 14:08
-
-
Save fabdarice/4fa60b980f4f745d294a to your computer and use it in GitHub Desktop.
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
$("#list_product").append("<p><%=j @product.name %></p>"); |
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
$('.product_id_<%= @product.id %>').remove(); |
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 @product, remote: true do |f| %> | |
<%= f.text_field :name %> | |
<% end %> | |
<div id="list_product"> | |
<% @products.each do |p| %> | |
<p class="product_id_<%= p.id %>"><%= p.name %></p> | |
<%= link_to "Delete", product_path(p), method: 'delete', data: {confirm: 'Are you sure?'}, remote: true %> | |
<% end %> | |
</div> |
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
def create | |
@product = Product.new(product_params) | |
@product.save | |
respond_to do |format| | |
format.html { render :nothing => true } | |
format.js { } | |
end | |
end | |
def destroy | |
@product = Selfie.find(params[:id]) | |
#session[:return_to] ||= request.referer | |
if (@product.destroy) | |
flash[:notice] = 'Product deleted.' | |
end | |
respond_to do |format| | |
format.html { render :nothing => true } | |
format.js { } | |
end | |
end | |
private | |
def product_params | |
params.require(:product).permit(:name) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment