Ruby-on-rails Rails 3:使用Simple_form 如何创建一个可以发布到专业#create 的表单?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4855801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:15:30  来源:igfitidea点击:

Rails 3: Using Simple_form how do I create a form that do a Post to specialities#create?

ruby-on-rails

提问by Nerian

Using Simple_form how do I create a form that do a Post to specialities#create?

使用 Simple_form 如何创建一个表单来发布到专业#create?

I tried this:

我试过这个:

<%= simple_form_for @course_group, :html => 
   { :method => 'post', 
     :action=> 'create', 
     :controller=>'specialities' }

But the form that is created is:

但是创建的表单是:

<form accept-charset="UTF-8" 
   action="/course_groups" 
   class="simple_form course_group" 
   controller="specialities" 
   id="new_course_group" 
   method="post">

What I expected is:

我的预期是:

<form accept-charset="UTF-8" 
   action="/specialities" 
   class="simple_form course_group" 
   controller="specialities" 
   id="new_course_group" 
   method="post">

回答by Nuby

Try using the :urloption, instead of including :action& :controllerright in the html hash. I would re-write your example as:

尝试使用该:url选项,而不是在 html 哈希中包含:action& :controllerright。我会将您的示例重新编写为:

<%= simple_form_for @course_group, 
    :url => url_for(:action => 'create', :controller => 'specialities'),
    :method => 'post' do |f| %>

Check out the actual form_forreference in http://api.rubyonrails.org

查看http://api.rubyonrails.org 中的实际form_for参考