【问题标题】:In my rails erb, how can i replace an ajax button_to by a link_to?在我的 rails erb 中,如何用 link_to 替换 ajax button_to?
【发布时间】:2011-08-30 13:32:42
【问题描述】:

我有以下按钮:

product), :remote => 真 %>

我想用一个包含带有文本的图像的链接来替换它。

我对 HTML CSS 部分没问题,但我希望请求是针对 line_items#create 而不是针对 line_items#index

我该怎么做?

【问题讨论】:

    标签: ruby-on-rails button link-to


    【解决方案1】:

    试试这个:

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

    别忘了更新 routes.rb ,例如:

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

    【讨论】:

      【解决方案2】:

      经过一番尝试和错误,我发现:

      <%= 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%>
      

      效果很好!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-05
        • 2012-09-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-09
        相关资源
        最近更新 更多