Rails 3:使用Simple_form 如何创建一个可以发布到专业#create 的表单? [英] Rails 3: Using Simple_form how do I create a form that do a Post to specialities#create?
本文介绍了Rails 3:使用Simple_form 如何创建一个可以发布到专业#create 的表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 Simple_form 创建一个可以发布到 Specialities#create 的表单?
Using Simple_form how do I create a form that do a Post to specialities#create?
我试过了:
<%= simple_form_for @course_group, :html =>
{ :method => 'post',
:action=> 'create',
:controller=>'specialities' }
但是创建的表单是:
<form accept-charset="UTF-8"
action="/course_groups"
class="simple_form course_group"
controller="specialities"
id="new_course_group"
method="post">
我的预期是:
<form accept-charset="UTF-8"
action="/specialities"
class="simple_form course_group"
controller="specialities"
id="new_course_group"
method="post">
推荐答案
尝试使用 :url
选项,而不是包含 :action
&:controller
就在 html 哈希中.我会将您的示例重写为:
Try using the :url
option, instead of including :action
& :controller
right in the html hash. I would re-write your example as:
<%= simple_form_for @course_group,
:url => url_for(:action => 'create', :controller => 'specialities'),
:method => 'post' do |f| %>
在 http://api.rubyonrails.orgform_for 参考>
Check out the actual form_for
reference in http://api.rubyonrails.org
这篇关于Rails 3:使用Simple_form 如何创建一个可以发布到专业#create 的表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文