开发者

In my rails erb, how can i replace an ajax button_to by a link_to?

开发者 https://www.devze.com 2023-04-01 07:02 出处:网络
I have the following button : <%= button_to \'Add to Cart\', line_items_path(:product_id => product),

I have the following button :

<%= button_to 'Add to Cart', line_items_path(:product_id => product), :remote => true %>

I want to replace it by a link_to containing an image with text on it.

I am ok with the HTML CSS part, but i want the request to be for line_items#create not for line_items#index

Ho开发者_StackOverfloww can i do that?


Try this:

<%= link_to "Add to Cart", {:controller => "line_items", :action => :create}, :remote => true %>

And don't forget to update routes.rb too, e.g.:

get "/blablabla", :to => "line_items#create"


After a bit of try and error i found that :

<%= link_to ("<div>Ajouter au panier</div>"+image_tag("some.jpg")).html_safe,
                                     line_items_path(:product_id => @product),
                                     :action => :create,
                                     :remote => true,:method => :post%>

It works perfectly fine!

0

精彩评论

暂无评论...
验证码 换一张
取 消