【问题标题】:rails link to another controllerrails 链接到另一个控制器
【发布时间】:2013-04-18 07:51:14
【问题描述】:
<td>
  <%=link_to image_tag(phone.image, :class => 'list_image'), :controller => 'phones_feature_controller', :action => 'index', :id => phone.id %>
</td>

我想要一个指向另一个控制器的图像链接。 这个链接在我的索引页中,它的控制器是phone。我有另一个控制器phones_feature。我想要一个指向phones_feature的索引页的链接

我的手机功能控制器:

 def index
  @phones=Phone.find(params[:id])
   respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @phones }
    end
  end

【问题讨论】:

    标签: ruby-on-rails ruby hyperlink controller


    【解决方案1】:

    您正在将控制器添加到您的控制器名称中。

    <%=link_to image_tag(phone.image, :class => 'list_image'),:controller => 'phones_feature', :action => 'index', :id=>phone.id %>
    

    查看url_for documentation

    【讨论】:

    • 我的phones_feature_controller 好吗?
    • 你的方法看起来不错,看看guides.rubyonrails.org/…的介绍。请记住,您需要继承 ApplicationController。
    猜你喜欢
    • 2015-11-01
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 2013-03-21
    • 2015-08-06
    • 1970-01-01
    相关资源
    最近更新 更多