- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我按照 Rails 入门教程稍作修改(在模型和属性的名称上),但我发现使用表单部分有问题。
我的“_form.erb.html”如下所示:
<%= form_for :company do |f| %>
<% if @company.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@company.errors.count, "error") %> evitaron que la compañía se almacenara
</h2>
<ul>
<% @company.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="input">
<%= f.label :name, "Nombre" %>
<%= f.text_field :name, :required => true%>
</div>
<div class="input">
<%= f.label :handle, "Handle" %>
<%= f.text_field :handle, :required => true%>
</div>
<div class="button">
<%= f.submit "Guardar" %>
</div>
<% end %>
我的 edit.html.erb 看起来像这样:
<h1>Editar empresa</h1>
<hr>
<%= render 'form' %>
<%= link_to 'Regresar al listado', companies_path %>
new.html.erb 看起来像这样:
<h1>Nueva empresa</h1>
<hr>
<%= render 'form' %>
<%= link_to 'Regresar al listado', companies_path %>
之前没有部分,我使用以下代码作为表单标题:
new.html.erb
<%= form_for :company, url: companies_path do |f| %>
edit.html.erb
<%= form_for :company, url: company_path(@company), method: :patch do |f| %>
现在我正在尝试使用部分我得到以下异常:
No route matches [POST] "/companies/new"
Rails.root: /../app
╔═══════════════════╦══════════════════════════╦═══════════════════════════════╦═══════════════════╗
║ Helper ║ HTTP Verb ║ Path ║ Controller#Action ║
╠═══════════════════╬══════════════════════════╬═══════════════════════════════╬═══════════════════╣
║ Path / Url ║ ║ ║ ║
║ companies_path ║ GET ║ /companies(.:format) ║ companies#index ║
║ POST ║ /companies(.:format) ║ companies#create ║ ║
║ new_company_path ║ GET ║ /companies/new(.:format) ║ companies#new ║
║ edit_company_path ║ GET ║ /companies/:id/edit(.:format) ║ companies#edit ║
║ company_path ║ GET ║ /companies/:id(.:format) ║ companies#show ║
║ PATCH ║ /companies/:id(.:format) ║ companies#update ║ ║
║ PUT ║ /companies/:id(.:format) ║ companies#update ║ ║
║ DELETE ║ /companies/:id(.:format) ║ companies#destroy ║ ║
║ pages_index_path ║ GET ║ /pages/index(.:format) ║ pages#index ║
║ root_path ║ GET ║ / ║ pages#index ║
╚═══════════════════╩══════════════════════════╩═══════════════════════════════╩═══════════════════╝
关于如何使用部分的任何想法?
最佳答案
成功
<%= form_for @company do |f| %>
代替
<%= form_for :company do |f| %>
来自Getting Started with Rails指南:
Everything except for the form_for declaration remained the same. The reason we can use this shorter, simpler form_for declaration to stand in for either of the other forms is that @article is a resource corresponding to a full set of RESTful routes, and Rails is able to infer which URI and method to use.
关于ruby-on-rails - "_form.erb.html"部分不适用于创建和更新表单代码生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30021987/
默认情况下_form.as._p吐出: Subject: 而我需要 Subject: 标签和输入之间有中断。我该如何修改Django代码? 最佳答案 您只是不能再使用form.a
我正在重构脚手架模板,但遇到了这个问题: 我试图从模板 _FORM.GSP 调用服务(一些安全逻辑) - 但在代码部分,而不是在输出部分 我已经阅读并尝试了这里的建议:How do I call a
我正在使用 Carrierwave 将图像字段添加到基于 Ryan Bates 修订的 #196 截屏视频的 Rails 嵌套模型。 Carrierwave 位基于他的截屏 #253 问答模型嵌套在类
我正在使用 Node js 请求模块向网站发送发布请求。查看网站请求后,它使用“表单数据”作为有效负载。该页面的内容类型是“application/x-www-form-urlencoded”。我的脚
我按照 Rails 入门教程稍作修改(在模型和属性的名称上),但我发现使用表单部分有问题。 我的“_form.erb.html”如下所示: evi
我试图在网站上提交表单,当我运行代码时,它给了我错误: mechanize._form.ParseError: nested FORMs 所以我查了一下,在网站上,有 2 个表格相互嵌套。 我需要的第
我有一些 javascript 来控制 _form 部分中的某些字段如何根据单击的单选按钮工作。当我输入新记录(新)操作时,一切正常,但在编辑期间,呈现相同的 _form 部分,javascript
我知道这是一个简单的问题,但我不记得你是如何在 Rails 中自动生成 View _form、edit、index、new 等的。我以为当您生成 Controller 和模型时,它会自动创建这些项目,
我想将使用 ActiveForm 和 Html Helper 的表单 View 呈现的 html 输出存储到我的 Controller 中的一个变量中。 我试过将 renderPartial 的结果直
我是 Ruby on Rails 的新手。我使用脚手架为 admin 创建模型 View 和 Controller 现在我的一位前辈告诉我为管理员更改_form.html.erb。我不知道如何实现它。
我正在使用 Devise 来管理用户,我的目标是让当前用户与创建的记录一起保存。 我曾尝试将当前用户保存在 Controller 或 _form 中,但无论哪种方式都失败了! 谢谢大家的帮助。 我的记
出于教学目的,我想生成展示单选按钮的脚手架。您可以生成带有复选框的脚手架: rails generate scaffold Person name:string honest:boolean bool
我是一名优秀的程序员,十分优秀!