Ruby on rails Ruby on Rails routes.rb不工作

Ruby on rails Ruby on Rails routes.rb不工作,ruby-on-rails,ruby,apache,routing,Ruby On Rails,Ruby,Apache,Routing,我正在升级现有的Rails应用程序。我想向routes.rb文件添加一个新路由,该文件链接到控制器中的函数。摘自原始working routes.rb文件: match 'items/:id/add_to_collection/:collection_pid' => 'items#add_to_collection', :via => [:get, :post] match 'items/:id/add_to_event/:event_pid' =>

我正在升级现有的Rails应用程序。我想向routes.rb文件添加一个新路由,该文件链接到控制器中的函数。摘自原始working routes.rb文件:

match 'items/:id/add_to_collection/:collection_pid'     =>  'items#add_to_collection', :via => [:get, :post]
match 'items/:id/add_to_event/:event_pid'       =>  'items#add_to_event', :via => [:get, :post]
控制器文件:

  #add to a task
  def add_to_collection
    @item = Item.find(params[:id])
    @collection_pid = params[:collection_pid]

    #does the item have a RELS-EXT datastream?
    @rels_ext_ds =  RELS_EXT_Datastream.new(:id => params[:id])
    if !@rels_ext_ds.nil?
         @rels_ext_ds.add_relation("fedora:isMemberOfCollection",{"rdf:resource","info:fedora/" + @collection_pid})
         @rels_ext_ds.save_to_fedora
    end
    render :text => "OK"
 end
  #add to an event
  def add_to_event
    @item = Item.find(params[:id])
    @event_pid = params[:event_pid]

    #does the item have a RELS-EXT datastream?
    @rels_ext_ds =  RELS_EXT_Datastream.new(:id => params[:id])
    if !@rels_ext_ds.nil?
    @rels_ext_ds.add_relation("fedora:isMemberOfEvent",{"rdf:resource","info:fedora/" + @event_pid})
    @rels_ext_ds.save_to_fedora
    end
    render :text => "OK"
  end
我想添加一个类似的函数,因此我将其添加到routes.rb文件中:

match 'items/:id/add_to_collection/:collection_pid'     =>  'items#add_to_collection', :via => [:get, :post]
match 'items/:id/add_to_event/:event_pid'       =>  'items#add_to_event', :via => [:get, :post]
和控制器文件:

  #add to a task
  def add_to_collection
    @item = Item.find(params[:id])
    @collection_pid = params[:collection_pid]

    #does the item have a RELS-EXT datastream?
    @rels_ext_ds =  RELS_EXT_Datastream.new(:id => params[:id])
    if !@rels_ext_ds.nil?
         @rels_ext_ds.add_relation("fedora:isMemberOfCollection",{"rdf:resource","info:fedora/" + @collection_pid})
         @rels_ext_ds.save_to_fedora
    end
    render :text => "OK"
 end
  #add to an event
  def add_to_event
    @item = Item.find(params[:id])
    @event_pid = params[:event_pid]

    #does the item have a RELS-EXT datastream?
    @rels_ext_ds =  RELS_EXT_Datastream.new(:id => params[:id])
    if !@rels_ext_ds.nil?
    @rels_ext_ds.add_relation("fedora:isMemberOfEvent",{"rdf:resource","info:fedora/" + @event_pid})
    @rels_ext_ds.save_to_fedora
    end
    render :text => "OK"
  end
但是,当我运行应用程序时(在重新启动Apache之后),应用程序会重定向,并且不会调用该函数。从日志文件:

Started GET "/app/items/123456/add_to_event/testerevent" for 192.168.102.22 at Tue Apr 08 15:42:18 +0200 2014
Processing by ItemsController#add_to_event as HTML
Parameters: {"id"=>"tcmp:123456", "event_pid"=>"testerevent"}
Redirected to https://localhost/app/login
Completed 302 Found in 87ms
我是否需要重新启动其他服务、以某种方式重建应用程序或清除一些缓存?我知道我在控制器中的函数内容是100%正确的,因为当我用新函数的内容替换原始函数的内容时,一切正常。我试图在我的新函数中打印一些日志,但没有找到日志,这表明从未调用过该函数。不过,它在日志文件中似乎是匹配的。我是不是忽略了什么?我对罗相当陌生。谢谢

编辑:

我找到了将我的应用重定向到登录页面的功能。在application_controller.rb文件中是一个名为check_authorization的函数

def check_authorization
  user = User.find(session['user'])
  unless user.roles.detect{|role|
    role.rights.detect{|right|
      right.action == action_name && right.controller == self.class.controller_path
    }
  }
  flash[:notice] = "Please log in to access the page you requested. (action "+action_name.to_s+", controller "+self.class.controller_path.to_s+")"
  #request.env["HTTP_REFERER"] ? (redirect_to :back) : (redirect_to :controller => 'users',:action=>'login') <-- This function
end
def检查\u授权
user=user.find(会话['user'])
除非user.roles.detect{| role|
role.rights.detect{| right|
right.action==action\u name&&right.controller==self.class.controller\u路径
}
}
flash[:notice]=“请登录以访问您请求的页面。(操作“+操作名称到“+”,控制器“+自身类.控制器路径到“+”)

#request.env[“HTTP_REFERER”]?(重定向到:返回):(重定向到:controller=>'users',:action=>'login')首先检查您正在使用的任何引擎是否与cancan类似

请参见日志文件中的“app/items/123456/add_to_event/testerevent”
它被重定向,因此 更改路线并检查是否正确不知道请再试一次

在路线前面添加“/”

match '/items/:id/add_to_event/:event_pid'       =>  'items#add_to_event', :via => [:get, :post]

我发现了问题。它与路由文件或功能无关,它是用户配置中未授予的某些权利。无论如何,谢谢你的努力

。。。它告诉你必须登录。你在使用cancan吗?如果你这样做了,你必须在你的能力文件中添加你的方法…向我们展示routes.rb文件我没有使用cancan gem。奇怪的是,我登录了,原来的功能正常工作。当我修改routes.rb文件以将新路由重定向到原始函数,并将原始路由重定向到新函数时,如:
match'items/:id/add_to_collection/:event_pid'=>'items#add_to_event',:via=>[:get,:post]
match'items/:id/add_to_event/:collection_pid'=>'items\add_to_collection',:via=>[:get,:post]
新的(第二)路径有效,但第一个路径无效。感谢您的输入,但添加斜杠并不能解决问题。我不认为路线本身就是问题(见我上面的评论)