加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – 来自辅助方法的意外点

发布时间:2020-12-17 01:29:04 所属栏目:百科 来源:网络整理
导读:我有以下路线 PosTracker::Application.routes.draw do get "home/index" resources :pos resources :apis match 'update_data' = 'home#update',:as = :update,:via = :get root :to = "home#index"end 现在,在使用link_to帮助器方法时: link_to "text",po
我有以下路线

PosTracker::Application.routes.draw do
  get "home/index"

  resources :pos
  resources :apis

  match 'update_data' => 'home#update',:as => :update,:via => :get
  root :to => "home#index"

end

现在,在使用link_to帮助器方法时:

link_to "text",pos_path(starbase)

我得到以下路线/pos.13而不是/ pos / 13.显然,这不会产生有效的输出.我怎样才能解决这个问题?

编辑:相关控制器:

class PosController < ApplicationController
  # GET /pos
  # GET /pos.xml
  def index
    #do stuff        

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @pos }
    end
  end

  # GET /pos/1
  # GET /pos/1.xml
  def show
    @pos = Pos.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @pos }
    end
  end
end

解决方法

在我看来,Rails正在将pos_path识别为你的#index动作url助手.通常,它会将您传递给资源的符号用于#show操作.

你想要使用的url帮助器

link_to "text",po_path(starbase)

您通常可以通过运行找到辅助方法的名称

rake routes

或者获取特定控制器的帮助程序

rake routes CONTROLLER=pos

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读