谁能告诉我,为什么我得到下面的错误?::的ActionView ::模板出错(字符串隐式转换为整数)
这是我states_controller.rb
:
def index
@states = State.all
end
而且在index.html.erb:
17 <form>
18 <select onchange="location = this.options[this.selectedIndex].value;">
19 <option>Select State…</option>
20 <% @states.each do |state| %>
21 <option value="<%= state.id %>">
22 <%= nytimes_state_name(state.name) %></option>
23 <% end %>
24 </select>
25 </form>
,当我在本地运行,但是一旦部署到Heroku上也能正常工作,我得到以下错误:
ActionView::Template::Error (no implicit conversion of String into Integer)
当我重新
46 <% @states.first(25).each do |state| %>
47 <li><%= link_to state.name.downcase + nytimes_state_abbrev(state.name), state %></li>>
48 <% end %>
然后我得到了同样的错误:移动nytimes_state_name
方法,直到遇到下一个块运行良好。
再次,当我删除nytimes_state_abbrev
方法时,它可以正常工作,直到它碰到下一个代码块,它也调用state.name
,并期望它是一个字符串。 (该name
值邮政编码abbreviations- CA
,,TX
,NY
,等等。)
你确定你使用的本地和在Heroku一样的宝石版本?尝试使用bundler在本地运行,即'bundle exec rails server'。 – dpassage 2014-09-30 15:49:39
它仍然罚款在本地运行,但你没有提醒我,我不得不修改的宝石,以避免一个实例变量的碰撞与我的'states'模型。我如何部署修改后的宝石? – 2014-09-30 15:52:39
这是一个完全不同的问题。 :)简短的回答或者直接嵌入源在Rails应用(http://stackoverflow.com/questions/6800074/custom-ruby-gem-in-gemfile-on-heroku),或叉Github上的宝石和在你的'Gemfile'中引用fork。基本上,把它放在Heroku可以看到的地方。 – dpassage 2014-09-30 16:01:11