【发布时间】:2011-08-30 13:32:42
【问题描述】:
我有以下按钮:
product), :remote => 真 %>
我想用一个包含带有文本的图像的链接来替换它。
我对 HTML CSS 部分没问题,但我希望请求是针对 line_items#create 而不是针对 line_items#index
我该怎么做?
【问题讨论】:
标签: ruby-on-rails button link-to
我有以下按钮:
product), :remote => 真 %>
我想用一个包含带有文本的图像的链接来替换它。
我对 HTML CSS 部分没问题,但我希望请求是针对 line_items#create 而不是针对 line_items#index
我该怎么做?
【问题讨论】:
标签: ruby-on-rails button link-to
试试这个:
<%= link_to "Add to Cart", {:controller => "line_items", :action => :create}, :remote => true %>
别忘了更新 routes.rb ,例如:
get "/blablabla", :to => "line_items#create"
【讨论】:
经过一番尝试和错误,我发现:
<%= 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%>
效果很好!
【讨论】: