开发者

rails foobar_path(3) returnes strange path: "/foobar.3/" instead of "/foobar/3/

开发者 https://www.devze.com 2022-12-27 20:37 出处:网络
Hi i have this starnge behavoir... <%= link_to image_tag(\"image.png\"), brain_path(1), :method => \"put\" %>

Hi i have this starnge behavoir...

<%= link_to image_tag("image.png"), brain_path(1), :method => "put" %>

produces:

<a href="/brain.1" onclick="var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.met ...[many rails code]... ;return false;"><img alt="Research_4" src="/images/image.png" /></a>

a href="/foobar.1" this is the strange part :( any ideas whqt is causing this?

rake routes gives the following:

new_brain GET /brain/new(.:format) {:controller=>"brains", :action=>"new"}

   edit_brain GET    /brain/edit(.:format)              {:controller=>"brains", :action=>"edit"}
        brain GET    /brain(.:format)                   {:controller=>"brains", :action=>"show"}
              PUT    /brain(.:format)                   {:controller=>"brains", :action=>"update"}
              DELETE /brain(.:format)  开发者_StackOverflow中文版                 {:controller=>"brains", :action=>"destroy"}
              POST   /brain(.:format)                   {:controller=>"brains", :action=>"create"}


  1. How do you route your foobar? (singular or plural? resource or resources?)

  2. Are you sure that you're using foobar_path(1), not foobars_path(1) (singular form)

in real life foobars_path(1) will return /foobars.1 and foobar_path(1) - /foobar/1

as I see you have to use brain_path(1) not brain_path(1)

UPD

Change your route.rb

map.resources :brain

it will be better if you'll rename your controller into pluralize brains - it is more conventional when you are using resources

0

精彩评论

暂无评论...
验证码 换一张
取 消