2009-09-16 2 views
0

Не могу понять, почему следующее генерирует «Строка не может быть принудительно введена в Fixnum».Строка не может быть принудительно введена в Fixnum (вызывающий цикл внутри метода в content_tag)

Любые идеи?

def branch_image 
    image_tag("24white/branch.png") 
    end 

    def spacing_images 
    i = 2 
    i.times do 
     image_tag("24white/blank.png") 
    end 
    end 

    def insert_branch(prefix, type) 
    content_tag(:li, spacing_images + branch_image + name_in_browser(prefix, type)) 
    end 

    def name_in_browser(prefix, type) 
    prefix + ": “" + truncate(type.name, :length => 20) + "”" 
    end 

Если я редактировать insert_branch следующим образом, весь пакет работает отлично:

def insert_branch(prefix, type) 
    content_tag(:li, branch_image + name_in_browser(prefix, type)) 
    end 

В следе, что я наклеенный ниже пунктов, app/helpers/application_helper.rb:31 является def insert_branch(prefix, type).

(Очевидно, в конце игры, чтобы вычислить i где-то, но пока я не получу эту работу, я просто присвоить значение его.)

Большое спасибо,

Стивен.

app/helpers/application_helper.rb:31:in `+' 
app/helpers/application_helper.rb:31:in `insert_branch' 
app/views/partials/_project_browser.haml:8 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/renderable.rb:39:in `send' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/renderable.rb:39:in `render' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/renderable_partial.rb:20:in `render' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:26:in `benchmark' 
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/core_ext/benchmark.rb:8:in `realtime' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:26:in `benchmark' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/renderable_partial.rb:19:in `render' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/template.rb:73:in `render_template' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/renderable_partial.rb:45:in `render_partial' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/partials.rb:152:in `render_partial' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/base.rb:258:in `render_without_haml' 
/Library/Ruby/Gems/1.8/gems/haml-2.2.3/lib/haml/helpers/action_view_mods.rb:11:in `render' 
/Library/Ruby/Gems/1.8/gems/haml-2.2.3/lib/haml/helpers.rb:96:in `non_haml' 
/Library/Ruby/Gems/1.8/gems/haml-2.2.3/lib/haml/helpers/action_view_mods.rb:11:in `render' 
app/views/layouts/application.html.haml:31 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/renderable.rb:39:in `send' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/renderable.rb:39:in `render' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/template.rb:73:in `render_template' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/base.rb:256:in `render_without_haml' 
/Library/Ruby/Gems/1.8/gems/haml-2.2.3/lib/haml/helpers/action_view_mods.rb:13:in `render' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/base.rb:371:in `_render_with_layout' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/base.rb:254:in `render_without_haml' 
/Library/Ruby/Gems/1.8/gems/haml-2.2.3/lib/haml/helpers/action_view_mods.rb:13:in `render' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1174:in `render_for_file' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:905:in `render_without_benchmark' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:51:in `render' 
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/core_ext/benchmark.rb:8:in `realtime' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:51:in `render' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/mime_responds.rb:135:in `send' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/mime_responds.rb:135:in `custom' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/mime_responds.rb:164:in `call' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/mime_responds.rb:164:in `respond' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/mime_responds.rb:158:in `each' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/mime_responds.rb:158:in `respond' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/mime_responds.rb:107:in `respond_to' 
app/controllers/projects_controller.rb:17:in `show' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in `send' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in `perform_action_without_filters' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:617:in `call_filters' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/rescue.rb:136:in `perform_action_without_caching' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:13:in `perform_action' 
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache' 
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/query_cache.rb:8:in `cache' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:12:in `perform_action' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in `send' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in `process_without_filters' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:606:in `process_without_session_management_support' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/session_management.rb:134:in `sass_old_process' 
/Library/Ruby/Gems/1.8/gems/haml-2.2.3/lib/sass/plugin/rails.rb:19:in `process' 
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:392:in `process' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:76:in `process' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `synchronize' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `process' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:282:in `run' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in `each' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in `run' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:128:in `run' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/command.rb:212:in `run' 
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281 
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in `load_without_new_constant_marking' 
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in `load' 
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in' 
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in `load' 
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require' 
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in' 
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require' 
+1

Можете ли вы также вставить все сообщение об ошибке, включая номер строки и трассировку стека? А также сообщите нам, по какому номеру строки начинается ваш отрывок. – sepp2k

+1

В фрагменте кода есть дополнительный токен конца. – khelll

ответ

1

Проблема в том, что times возвращает номер, на который он был вызван, поэтому spacing_images возвращает то же значение. Попробуйте следующее:

def spacing_images 
    returning([]) do |images| 
    3.times { images << helper.image_tag("24white/dot.png") } 
    end.join(' ') 
end 
0

Я уверен, что ошибка не из предыдущего фрагмента кода, мне не удалось воспроизвести этот случай в консоли (сценарий/консоли):

i = 3 
i.times do 
    helper.image_tag("24white/dot.png") 
end 
#<img alt="Dot" src="/images/24white/dot.png" /> 
#<img alt="Dot" src="/images/24white/dot.png" /> 
#<img alt="Dot" src="/images/24white/dot.png" /> 
#=> 3 

Скорее всего проблема в другой части кода.

+0

Ищите контекст, в котором вызывается spacing_images. –

2

times возвращает номер, который вы отправляете, поэтому вы говорите 2 + "24white/branch.png" + name_in_browser(prefix, type). Я думаю, вы хотите реализовать spacing_images как image_tag("24white/blank.png") * 2.

+0

Thanks Chuck, Вы говорите, что я пишу следующее? content_tag (: li, [image_tag ("24white/blank.png"), image_tag ("24white/blank.png")] + branch_image + name_in_browser (prefix, type)) Если вы беспокоитесь, я буду теряют способность вычислять значение «i» динамически. –

+0

Это была ошибка с моей стороны. Я обновил свой ответ. Вы можете сохранить вызов метода spacing_images, если хотите, просто выполните его, как я сказал выше, вместо использования 'times'. – Chuck

+0

Мои спецификации проходят с "image_tag (" 24white/blank.png ") * i". Ура! –

Смежные вопросы