regex - Rails - "can't convert Symbol into String" on Production ONLY -


i have partial view displays model-specific flash messages. partial looks like:

app/views/mymodel/_flashpartial.erb

<% flash.each |key, value| %>   <% if model_key = mymodelflash(key) %>     <%= content_tag(:div, value, :class => "flash #{model_key}") %>   <% end %> <% end %> 

the mymodelflash method takes key , checks particular prefix using simple regex. it's located in

app/helpers/mymodelhelper.rb

module mymodelhelper   def mymodelflash( key )     m = /^_mymodel_(.*)/.match(key)     m[1] unless m.nil?   end end 

this works fine in development , test environments. goes onto heroku, error saying (actionview::template::error) "can't convert symbol string" pointing call match.

if remove call mymodelflash view , display key , value, works fine in terms of not erroring out, @ least key , value getting partial view fine. reason helper method thinks key being passed symbol , not string.

any ideas why might happening?

i suggest use key.to_s quick workaround.

the reason problem may version of component differs between testing server , production server. if tests pass, , production environment crashes, bad situation.

you should compare versions of ruby , of gems using. if use 'bundler' 'bundle list' gives nice summary.

if find out versions same... well, looking reason.

update

as seems problem caused not version differences, unexpected data in flash, in production environment may different in testing.

i suggest change mymodelflash method little.

def mymodelflash( key )   if m = /^_mymodel_(.*)/.match(key.to_s)     return m[1]   end end 

the flash may contain different keys, of them may symbols or anything, must prepared handle of them.

converting key parameter .to_s should safe choice, if sure set flash keys (i mean keys related "_mymodel" issue) strings, may change first line of method:

def mymodelflash( key )   if key.is_a?(string) && m = /^_mymodel_(.*)/.match(key.to_s)     return m[1]   end end 

and in test, add few other keys flash, , test how action handles them.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -