Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.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_Error Handling_Simple Form - Fatal编程技术网

Ruby on rails 简单表单是否适用于嵌套对象?

Ruby on rails 简单表单是否适用于嵌套对象?,ruby-on-rails,error-handling,simple-form,Ruby On Rails,Error Handling,Simple Form,我有两个表单,1显示正确的错误通知,2不显示t。我不知道为什么 One: 公告表格: 它有公告变量,announcement=@announcement <%= simple_form_for announcement do |f| %> <%= f.input :title, label: "Nazwa", placeholder: "Tytuł Posta", error: "Proszę podać tytuł" %> <%= f.input :me

我有两个表单,1显示正确的错误通知,2不显示
t。我不知道为什么

One: 公告表格:

它有公告变量,
announcement=@announcement

<%= simple_form_for announcement do |f| %>

  <%= f.input :title, label: "Nazwa", placeholder: "Tytuł Posta", error: "Proszę podać tytuł" %>
  <%= f.input :message, label: "Treść", placeholder: "Treść Posta", error: "Post musi posiadać treść", as: :text, input_html: { 'rows' => 12 } %>
  <%= f.submit  "Dodaj Newsa ;)", class: 'btn btn-primary' %>
<% end %>
和两个:

字符表:

<article class="character_form ">
  <%= simple_form_for [@user, @user.characters.new] do |f| %>

    <%= f.input :name, label: "Imię", placeholder: "Imię postaci", error: "Proszę podać imię postaci" %>
    <%= f.input :clan, collection: CLAN_NAMES_ARRAY, label: "Klan:", include_blank: false  %>
    <%= f.input :family, label: "Rodzina:", include_blank: false %>
    <%= f.input :desc, label: "Opis Postaci:", placeholder: "Opisz swoją postać...", error: "Postać musi posiadać opis" %>
    <%= f.submit "Zapisz", class: "btn btn-primary" %>

  <% end %>
</article>
这两种都是非常标准的东西,我遇到的问题是,在第一个示例中,simple_表单返回很好的验证通知,而在第二个表单中则没有。这两种形式之间唯一的区别是character对象是嵌套对象(@user.character),而announcement不是。我对这两种模型都进行了状态验证

我的问题是:


简单表单是否显示嵌套OBEJCT的错误通知?(我认为应该)。如果是,我的代码有什么问题阻止了第二种形式的使用

问题出现在我的控制器和表单中

对控制器有帮助的是,改变:

@character=@user.characters.new
@character=character.new

以我的形式:

<article class="character_form ">
  <%= simple_form_for [@user, @user.characters.new] do |f| %>

    <%= f.input :name, label: "Imię", placeholder: "Imię postaci", error: "Proszę podać imię postaci" %>
    <%= f.input :clan, collection: CLAN_NAMES_ARRAY, label: "Klan:", include_blank: false  %>
    <%= f.input :family, label: "Rodzina:", include_blank: false %>
    <%= f.input :desc, label: "Opis Postaci:", placeholder: "Opisz swoją postać...", error: "Postać musi posiadać opis" %>
    <%= f.submit "Zapisz", class: "btn btn-primary" %>

  <% end %>
</article>
  def create
    @user = User.find(params[:user_id])
    @character = @user.characters.new(character_params)

    if @character.save
      redirect_to current_user
    else
      render :new
    end
  end