控制器动作不会像它应该的那样在@中存储值

时间:2011-12-24 18:16:57

标签: ruby-on-rails

我有以下关系:

hero.rb -> has_many :builds
build.rb -> belongs_to :hero

的routes.rb

resources :heros, :path => '/heroes' do
  resources :builds
end

index操作中,以下代码可以完美地找出网址中的英雄( http:// localhost:3000 / heroes / tiny / builds )特定英雄的构建。

@hero = Hero.find(params[:hero_id]) 

为什么相同的代码在show操作中没有工作,其中包含网址 http:// localhost:3000 / heroes / tiny / builds / the-best-build-ever ? 以下代码似乎都没有像我们应该那样存储变量:

@hero = Hero.find(params[:hero_id]) 
@build = Build.find(params[:id])


以下是开发日志文件中的参数:https://gist.github.com/1518721


Github Repo:https://github.com/imjp/DotA-Items
我一直在努力解决这个问题几个小时,我似乎无法弄明白:/

1 个答案:

答案 0 :(得分:3)

查看你的github repo,你已经在你的构建控制器中定义了show方法两次。这意味着不会加载任何变量,因为该方法的第二个实例只是空白。

相关问题