Reputation: 181
Can someone tell me why I'm getting the following error?
This is my states_controller.rb
:
def index
@states = State.all
end
And in 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>
This works fine when I run it locally, but once deployed to Heroku, I get the following error:
ActionView::Template::Error (no implicit conversion of String into Integer)
When I remove the nytimes_state_name
method, it runs fine until it hits the next block:
46 <% @states.first(25).each do |state| %>
47 <li><%= link_to state.name.downcase + nytimes_state_abbrev(state.name), state %></li>>
48 <% end %>
And then I get the same error.
And again, when I remove nytimes_state_abbrev
method, it works fine until it hits the next block of code, which also calls state.name
and expects it to be a string. (The name
values are postal code abbreviations—CA
, AZ
, TX
, NY
, and so forth.)
Upvotes: 0
Views: 1095
Reputation: 5453
The basic answer as to why OP was seeing different behavior on his local build and on Heroku was because he had made modifications to one of the gems he was using, and those modifications weren't getting pushed when he deployed.
The solution is to either embed the source of the gem directly in your Rails app, as in this question, or fork the gem on Github and reference the fork in the Gemfile
. Sounds like he chose the former, and now has consistent behavior between his local build and Heroku.
Upvotes: 1