Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 粒子场未定义的局部变量或方法'f';_Ruby On Rails - Fatal编程技术网

Ruby on rails 粒子场未定义的局部变量或方法'f';

Ruby on rails 粒子场未定义的局部变量或方法'f';,ruby-on-rails,Ruby On Rails,我有3个粒子,里面有形状。我在“编辑视图”页面上调用这些粒子。我在尝试定义f时,遇到了一个错误,我说“未定义的局部变量或方法'f'”,但我相信我对使用什么语法和约定感到困惑。我相信我很接近,但我有点困惑 views/ideas/edit.html.erb <%= render :partial => "ideas_nav" %> <h1><%= @idea.working_name %></h1> <div id="idea_sho

我有3个粒子,里面有形状。我在“编辑视图”页面上调用这些粒子。我在尝试定义f时,遇到了一个错误,我说“未定义的局部变量或方法'f'”,但我相信我对使用什么语法和约定感到困惑。我相信我很接近,但我有点困惑

views/ideas/edit.html.erb

<%= render :partial => "ideas_nav" %>

<h1><%= @idea.working_name %></h1>

<div id="idea_show_container">
 <%= form_for @idea  do |f| %>
 <div id="basic_details" class="idea-show-columns">
   <%= render :partial => 'idea_basic_edit', @ideas => {:f => f} %>
   <%= render :partial => 'comments', @ideas => {:f => f}  %>
   <%= render :partial => 'mockups', @ideas => {:f => f} %>
</div>

<% if current_user.has_copywriter_access? %>
   <div id="copy_details" class="idea-show-columns">
    <%= render :partial => 'copy_edit', @ideas => {:f => f}  %>
   </div>
<% end %>


<% if current_user.has_artist_access? %>
    <div id="art_details" class="idea-show-columns ">
        <%= render :partial => 'art_edit', @ideas => {:f => f} %>
    </div>
<% end %>

</div>

  <%= f.submit %>
  <%end%>
<%= render :partial => "ideas_nav" %>

<h1><%= @idea.working_name %></h1>

<div id="idea_show_container">
  <%= form_for @idea  do |f| %>
    <div id="basic_details" class="idea-show-columns">
      <%= render :partial => 'idea_basic_edit', :locals => {:f => f} %>
      <%= render :partial => 'comments', :locals => {:f => f}  %>
      <%= render :partial => 'mockups', :locals => {:f => f} %>
    </div>

    <% if current_user.has_copywriter_access? %>
       <div id="copy_details" class="idea-show-columns">
        <%= render :partial => 'copy_edit', :locals => {:f => f}  %>
       </div>
    <% end %>

    <% if current_user.has_artist_access? %>
        <div id="art_details" class="idea-show-columns ">
            <%= render :partial => 'art_edit', :locals => {:f => f} %>
        </div>
    <% end %>

    <%= f.submit %>

  <% end %>
</div>
日志:


你想要的是
:本地人而不是
@ideas
。像这样:

<%= render :partial => 'idea_basic_edit', :locals => {:f => f} %>
'idea\u basic\u edit',:locals=>{:f=>f}%>

这将使值
f
在partial中可用。

您想要的是
:locals
而不是
@ideas
。像这样:

<%= render :partial => 'idea_basic_edit', :locals => {:f => f} %>
'idea\u basic\u edit',:locals=>{:f=>f}%>

这将使部分中的值
f
可用。

您认为
@ideas
来自哪里?你试过这个吗:

views/ideas/edit.html.erb

<%= render :partial => "ideas_nav" %>

<h1><%= @idea.working_name %></h1>

<div id="idea_show_container">
 <%= form_for @idea  do |f| %>
 <div id="basic_details" class="idea-show-columns">
   <%= render :partial => 'idea_basic_edit', @ideas => {:f => f} %>
   <%= render :partial => 'comments', @ideas => {:f => f}  %>
   <%= render :partial => 'mockups', @ideas => {:f => f} %>
</div>

<% if current_user.has_copywriter_access? %>
   <div id="copy_details" class="idea-show-columns">
    <%= render :partial => 'copy_edit', @ideas => {:f => f}  %>
   </div>
<% end %>


<% if current_user.has_artist_access? %>
    <div id="art_details" class="idea-show-columns ">
        <%= render :partial => 'art_edit', @ideas => {:f => f} %>
    </div>
<% end %>

</div>

  <%= f.submit %>
  <%end%>
<%= render :partial => "ideas_nav" %>

<h1><%= @idea.working_name %></h1>

<div id="idea_show_container">
  <%= form_for @idea  do |f| %>
    <div id="basic_details" class="idea-show-columns">
      <%= render :partial => 'idea_basic_edit', :locals => {:f => f} %>
      <%= render :partial => 'comments', :locals => {:f => f}  %>
      <%= render :partial => 'mockups', :locals => {:f => f} %>
    </div>

    <% if current_user.has_copywriter_access? %>
       <div id="copy_details" class="idea-show-columns">
        <%= render :partial => 'copy_edit', :locals => {:f => f}  %>
       </div>
    <% end %>

    <% if current_user.has_artist_access? %>
        <div id="art_details" class="idea-show-columns ">
            <%= render :partial => 'art_edit', :locals => {:f => f} %>
        </div>
    <% end %>

    <%= f.submit %>

  <% end %>
</div>
“创意导航”%>
“想法”\u基本编辑“,:locals=>{:f=>f}%>
'comments',:locals=>{:f=>f}%>
‘实体模型’,:locals=>{:f=>f}%>
'copy_edit',:locals=>{:f=>f}%>
‘艺术编辑’,:locals=>{:f=>f}%>

在你看来,
@ideas
来自哪里?你试过这个吗:

views/ideas/edit.html.erb

<%= render :partial => "ideas_nav" %>

<h1><%= @idea.working_name %></h1>

<div id="idea_show_container">
 <%= form_for @idea  do |f| %>
 <div id="basic_details" class="idea-show-columns">
   <%= render :partial => 'idea_basic_edit', @ideas => {:f => f} %>
   <%= render :partial => 'comments', @ideas => {:f => f}  %>
   <%= render :partial => 'mockups', @ideas => {:f => f} %>
</div>

<% if current_user.has_copywriter_access? %>
   <div id="copy_details" class="idea-show-columns">
    <%= render :partial => 'copy_edit', @ideas => {:f => f}  %>
   </div>
<% end %>


<% if current_user.has_artist_access? %>
    <div id="art_details" class="idea-show-columns ">
        <%= render :partial => 'art_edit', @ideas => {:f => f} %>
    </div>
<% end %>

</div>

  <%= f.submit %>
  <%end%>
<%= render :partial => "ideas_nav" %>

<h1><%= @idea.working_name %></h1>

<div id="idea_show_container">
  <%= form_for @idea  do |f| %>
    <div id="basic_details" class="idea-show-columns">
      <%= render :partial => 'idea_basic_edit', :locals => {:f => f} %>
      <%= render :partial => 'comments', :locals => {:f => f}  %>
      <%= render :partial => 'mockups', :locals => {:f => f} %>
    </div>

    <% if current_user.has_copywriter_access? %>
       <div id="copy_details" class="idea-show-columns">
        <%= render :partial => 'copy_edit', :locals => {:f => f}  %>
       </div>
    <% end %>

    <% if current_user.has_artist_access? %>
        <div id="art_details" class="idea-show-columns ">
            <%= render :partial => 'art_edit', :locals => {:f => f} %>
        </div>
    <% end %>

    <%= f.submit %>

  <% end %>
</div>
“创意导航”%>
“想法”\u基本编辑“,:locals=>{:f=>f}%>
'comments',:locals=>{:f=>f}%>
‘实体模型’,:locals=>{:f=>f}%>
'copy_edit',:locals=>{:f=>f}%>
‘艺术编辑’,:locals=>{:f=>f}%>

这更有意义。非常感谢。我不再收到错误,但由于某些原因,我在表单中所做的任何更改在单击“提交”时都不会得到更新。你知道为什么会这样吗?在较新的RoR/Ruby(如RoR 4和Ruby 2)上您还可以将代码简化为:
关于更新问题:您需要发布控制器配置。我将检查控制器如何处理返回的所有字段,并监视日志,以查看表单中的请求参数。您可能还想研究在
\u idea\u basic\u edit.erb
部分中为
使用
f.fields\u。文档:@CDub:I不认为有必要为
设置
f.field\u,因为这不应该是嵌套表单。@AWM-您可能是对的,但没有看到控制器代码,这只是一种可能的预感。:)这更有意义。非常感谢。我不再收到错误,但由于某些原因,我在表单中所做的任何更改在单击“提交”时都不会得到更新。你知道为什么会这样吗?在较新的RoR/Ruby(如RoR 4和Ruby 2)上您还可以将代码简化为:
关于更新问题:您需要发布控制器配置。我将检查控制器如何处理返回的所有字段,并监视日志,以查看表单中的请求参数。您可能还想研究在
\u idea\u basic\u edit.erb
部分中为
使用
f.fields\u。文档:@CDub:I不认为有必要为
设置
f.field\u,因为这不应该是嵌套表单。@AWM-您可能是对的,但没有看到控制器代码,这只是一种可能的预感。:)请注意Rails4.2的另一个答案中AWM的注释,它似乎不再支持“局部变量”方法,使旧的、以前工作的代码中断,并出现与OP相同的错误。请注意Rails4.2的另一个答案中AWM的注释,它似乎不再支持“局部变量”方法,使其更旧,以前工作的代码中断,错误与OP相同。