Tag: form for

当使用浅层路由时,不同的路由需要不同的form_for参数

我在这里使用简单的表单,但这也是普通的Rails表单的一个问题。 在使用浅层路由时,form_for需要不同的参数,具体取决于它使用的上下文。 例如:为了编辑( http://localhost:3000/notes/2/edit ),_form.html.erb需要有simple_form_for(@note) 。 但是为了创build一个新的注释( http://localhost:3000/customers/2/notes/new )_form.html.erb需要simple_form_for([@customer, @note]) 。 如果要么收到错误的参数,我会得到一个方法找不到错误。 处理这个问题的最好方法是什么? 我可以制作两个单独的表格,但是看起来很乱。 我必须为后面的链接设置@customer,但是我可以在表单中使用一个不同的variables(比如@customer_form),而不是在编辑和更新方法中设置它,但是这不一致并且有些混乱,因为我会必须在新方法中设置@customer_form和@customer。 我可以做这个人做的事情,并将其分成多个文件。 它看起来像迄今为止最好的select,但我不太喜欢它,因为你不能只打开_form.html.erb,看看发生了什么。 这些是我唯一的select吗? 示例如下: configuration/ routes.rb中 Billing::Application.routes.draw do resources :customers, :shallow => true do resources :notes end end 耙路线| grep说明 customer_notes GET /customers/:customer_id/notes(.:format) notes#index POST /customers/:customer_id/notes(.:format) notes#create new_customer_note GET /customers/:customer_id/notes/new(.:format) notes#new edit_note GET /notes/:id/edit(.:format) notes#edit note GET /notes/:id(.:format) notes#show PUT […]

Rails不可编辑的文本字段

我有一个form_for以下面的方式写成: <div class="field"> <%= location.label :city %> <%= location.text_field :city, :disabled=>true%> </div> <div class="field"> <%= location.label :country %> <%= location.text_field :country, :disabled=>true%> </div> 正如你所看到的2文本域被禁用,因为它们由jquery函数自动填充,我不想让用户处理它们。 问题是这样,视图doesen不会传递参数给控制器,因为被禁用! 是否有任何其他方式传递不可编辑的text_field到控制器,注意我不想使用隐藏的领域,因为我想显示结果给用户在一个文本框 TNX

自定义文本的轨道form_for标签

我想在form_for显示一个标签: <div class="field"> <%= f.label :name %><br /> <%= f.text_field :name %> </div> 这将生成标签“名称”,但我希望它是“你的名字”。 我怎样才能改变它?

rails simple_form – 隐藏字段 – 创build?

你怎么能有一个简单的forms隐藏领域? 以下代码: = simple_form_for @movie do |f| = f.hidden :title, "some value" = f.button :submit 导致这个错误: undefined method `hidden' for #SimpleForm::FormBuilder:0x000001042b7cd0