Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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 为“模型内轨道”对话框添加表格_Ruby On Rails_Ruby On Rails 4_Form For - Fatal编程技术网

Ruby on rails 为“模型内轨道”对话框添加表格

Ruby on rails 为“模型内轨道”对话框添加表格,ruby-on-rails,ruby-on-rails-4,form-for,Ruby On Rails,Ruby On Rails 4,Form For,我有家庭控制器和电子邮件控制器。在home controller中,我有一个模型对话框来更新电子邮件选项卡中的字段 所以我在home controller中创建了一个方法来创建新的电子邮件字段,如下所示 def esave @email = Email.new(user_params) if !user_params.nil? if @email.save_with_captcha flash[:notice] = "Thank you for registeri

我有家庭控制器和电子邮件控制器。在home controller中,我有一个模型对话框来更新电子邮件选项卡中的字段

所以我在home controller中创建了一个方法来创建新的电子邮件字段,如下所示

  def esave
  @email = Email.new(user_params)
  if !user_params.nil?
    if @email.save_with_captcha
      flash[:notice] = "Thank you for registering you email address"
      redirect_to :action => 'new'
    else
      render 'new'
    end
  end
结束

现在我想在我的主控制器视图中访问此方法。我试着用这个

  <%= form_for(@email, url: home_esave_path, :html => {class:"form-signin"}) do |f| %>
< % end % >
{class:“表单签名”})do | f |%>
<%end%>
但这是一个错误

ActionView::Template::Error (First argument in form cannot contain nil or be empty):
App 31348 stderr:     100:  </div>
App 31348 stderr:     101: 
App 31348 stderr:     102:  <!-- Modal -->
App 31348 stderr:     103:  <%= form_for(@email, url: home_esave_path,    :html => {class:"form-signin"}) do |f| %>
App 31348 stderr:     104:  <% if @email.errors.any? %>
App 31348 stderr:     105:  <div id="error_explanation">
App 31348 stderr:     106:    <h2>
App 31348 stderr:   app/views/home/index.html.erb:103:in ` _app_views_home_index_html_erb__972726411912165480_69960653266320'
ActionView::Template::Error(表单中的第一个参数不能包含nil或为空):
App 31348标准:100:
App 31348标准:101:
App 31348标准:102:
App 31348标准:103:{class:“表单签名”})do | f |%>
App 31348标准:104:
App 31348标准:105:
App 31348标准:106:
App 31348 stderr:App/views/home/index.html.erb:103:in`_App_views_home_index_html_erb_972726411912165480_69960653266320'
我没有添加模型对话框代码,因为它是纯html。关于如何在home controller视图中使用email controller对象的任何建议。

更改此选项:

<%= form_for(@email, url: home_esave_path, :html => {class:"form-signin"}) do |f| %>
{class:“表单签名”})do | f |%>
为此:

<%= form_for(@email||Email.new, url: home_esave_path, :html => {class:"form-signin"}) do |f| %>
{class:“表单签名”})do | f |%>

@email变量为空,您需要在主控制器的索引操作中实例化它。是的,感谢它有效创建-还有一个建议,因为您正在创建一个新的电子邮件对象,请使用电子邮件控制器中的
create
操作。如果执行此操作,则不需要在表单_中包含url:参数。这就是他们所说的“restful”的意思,这将有助于保持代码之间的良好分离。好的,谢谢,我将进行更改…;)
<%= form_for(@email||Email.new, url: home_esave_path, :html => {class:"form-signin"}) do |f| %>