Ruby on Rails:link_to表现得很奇怪

时间:2010-07-12 14:52:24

标签: ruby-on-rails

所以......这是我的link_to

  • <%= link_to“Archive”,:action => 'archive'%>
  • 和我在控制台中的输出

     Parameters: {"action"=>"archive", "controller"=>"achievables"}
    

    为什么动作不“归档”? 该方法在控制器中定义...拼写正确且一切。

    编辑: 来自routes.rb

      map.archives 'achievable/archive', :controller => 'achievables', :action => 'archive'
    
      map.resources :achievables, :member => {:build => [:get,:post], :publish_detail => [:get,:post], :publish=>[:get,:post], :confirm_publish=>[:get,:post], :confirm_delete=>[:get,:post]}
    

    现在,错误是

    Showing app/views/layouts/build_archivable.html.erb where line #6 raised:
    
    Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
    

    这又是错误的道路。 = \

    1 个答案:

    答案 0 :(得分:1)

    尝试将操作指定为字符串而不是符号:

    <%= link_to 'Archive', :action => 'archive' %>
    

    或者,您可能在config/routes.rb内定义了更高优先级的路由,该路由在默认/:controller/:action/:id路由之前匹配(Rails从文件顶部开始并向下工作,直到达到路径为止匹配网址。