【问题标题】:Ruby link_to controllerRuby link_to 控制器
【发布时间】:2017-05-02 04:47:49
【问题描述】:

如果我在app/views/schools/edit.html.erb 中有以下行,rails 是否假定 控制器 被称为school_controller.rb?它如何确定要查看哪个控制器

link_to 'Check teachers', :action => :check_teachers, :id => @school.id

【问题讨论】:

    标签: ruby-on-rails path controller link-to


    【解决方案1】:
    link_to 'Check teachers', :action => :check_teachers, :id => @school.id
    

    Rails 从 "params[:controller]" 中挑选它,这是这个的“学校”。

    如果你想要不同的,你需要在 link_to 中传递 :controller 选项

    【讨论】:

      【解决方案2】:

      您可以在link_to 标签中传递控制器,例如:

      link_to 'Check teachers', :controller => "schools" :action => "check_teachers", :id => @school.id
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多