gpt4 book ai didi

html - Ruby on Rails-simple_form_for如何显示每个字段的错误

转载 作者:行者123 更新时间:2023-12-03 08:48:09 24 4
gpt4 key购买 nike

我想在每个字段下显示错误,我的html.erb如下:

<%= simple_form_for [:admin, @municipality, @subdomain], :html => {:class => ''} do |f| %>

<%= f.input :subdomain, hint: 'Dominio senza senza http://', error: true%>

<%= f.input :subdomain_type, as: :select, collection: [['Sito','S'],['Api','A']] %>
<%= f.input :active %>
<%= f.input :draft,
hint: 'Si applica ai siti e indica se il sito è una bozza interna (e quindi non deve essere raggiungibile dai motori di ricerca)',
label: 'È una bozza' %>
<div class="form-actions">
<%= f.button :submit, :class => 'btn-primary', :value => 'Salva' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
admin_municipality_subdomains_path, :class => 'btn' %>
</div>
<% end %>

@subdomain 变量中,我具有“错误”属性,可将错误的完整列表返回给我,问题是:如何在子域字段下显示它?

在此处编辑 Controller 代码:
class Admin::SubdomainsController < InheritedResources::Base
layout 'admin'
before_filter :authenticate_admin!
before_filter :set_page_title
load_and_authorize_resource
actions :all, except: [:show]

belongs_to :municipality
add_breadcrumb Subdomain.model_name.human(:count => 2).titleize, :admin_municipality_subdomains_path

def index
@subdomain = Subdomain.new
index!
end

def create
create! {
@municipality = Municipality.find(params[:municipality_id])
admin_municipality_subdomains_path
}
end

def destroy
@municipality = Municipality.find(params[:municipality_id])
@subdomain = Subdomain.find(params[:id])
destroy!
end

private
def permitted_params
params.permit(:subdomain => [:active, :subdomain, :blocked, :subdomain_type, :draft])
end

def set_page_title
@page_title = Subdomain.model_name.human(:count => 2).titleize
end
end

最佳答案

我想你可以添加类似

<%= @subdomain.errors if @subdomain.errors %>


 <%= f.input :subdomain, hint: 'Dominio senza senza http://', error: true%>

关于html - Ruby on Rails-simple_form_for如何显示每个字段的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48707140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com