2015-09-07 83 views
0

我有下面的代码:如何将局部变量传递到另一个视图?

帖子/ _form.html.haml

- cat = Post::CATEGORIES.map { |c| [t(c, scope: :post_categories), c] } 
= f.input :category, collection: cat 
= f.input :subject, input_html: { class: 'input-block-level' } 
= f.input :body, input_html: { rows: 5, class: 'ctrlenter input-block-level expanding' } 
= link_to "#", class: 'smiley', role: 'add_smiley', tabidex: 4 do 
    %i.icon.icon-smile 
    смайлы 
= smiles_helper '#post_body' 

.form-horizontal 
    = f.input :tag_list, input_html: { class: 'input-block-level' } 
    - if (current_user.paid? && current_user.moderated_group_ids.include?(@group.id)) || moderator? 
    = f.input :comments_disabled, inline_label: true, label: false 
.attachments 
    = f.simple_fields_for :attachments do |af| 
    = render "attachments/#{af.object.asset_type.underscore}", :f => af 
.poll{style: "display: none;"} 
    %h1 "Новый опрос" 
    = f.simple_fields_for :poll do |post| 
    = render "polls/poll_fields", f: post 

民调/ poll_fields.html.haml

= f.error_messages header_message: nil 
= f.input :question, disabled: [email protected]?(current_user), input_html: { class: 'input-block-level' } 
= f.input :results_hidden, as: :boolean, inline_label: 'Скрыть результаты до окончания опроса', label: false 
= f.input :from_date, as: :datetime, input_html: { class: 'poll_date' } 
= f.input :to_date, as: :datetime, input_html: { class: 'poll_date' } 
%h3#poll-items Варианты ответа (не больше пяти) 
.item_index 
    = f.simple_fields_for :poll_items do |poll| 
    = render template: "polls/poll_item_fields", f: poll 
    = link_to_add_association 'Добавить еще вариант', f, :poll_items, 
           { 'data-association-insertion-method' => 'before', 
           'data-association-insertion-traversal' => 'next' } 

民调/ poll_item_fields.html。 haml

.poll_row 
    .poll_item 
    = f.input :answer, input_html: { class: 'ctrlenter expanding' }, label: false, placeholder: 'Введите вариант ответа' 
    = link_to_remove_association "удалить", f, { wrapper_class: 'poll_item' } 

显示错误:显示... /视图/轮询/ poll_item_fields.html.haml其中线路#3提出:

未定义局部变量或方法`F”为#<#:0xbe2d1a2c>

如何正确地将变量f传递给polls/poll_item_fields.html.haml?的

回答

0

代替 render template: "polls/poll_item_fields", f: poll

尝试 render "polls/poll_item_fields", f: poll

+0

显示错误:显示... /视图/调查/ _poll_fields.html.haml在行#9提出: 缺少的部分民调/ poll_item_fields –

+0

SRY我的错。那么'render模板:“polls/poll_item_fields”,当地人:{f:poll}'怎么样? – djaszczurowski

+0

显示../views/polls/_poll_fields.html.haml在哪里行#10提出: 缺少部分帖子/ poll_item_fields –

相关问题