0

我为收款公司的详细信息创建了一个表格。如果表单详细信息被保存,它是

重定向到下一页。我的问题是单击保存按钮后它正在重定向但显示“连接已重置”

我的routes.rb文件

 get 'companies/new'
 match 'companies/create' => 'companies#create' , :as => "create_companies_path" , :via => "post"
 match 'companies/upload' => 'companies#upload'
 resources :companiesde 

我最新的开发日志详情

     Started POST "/companies/create" for at 2013-05-09 11:24:02 +0530
Processing by CompaniesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"J7AnRNRpqHGvPTzc1qlbn9/X5ITA8T0HaibAgqD+qrI=", "companies"=>{"f_name"=>"Ghayathri", "l_name"=>"Angamuthu", "email"=>"aghayathri@gmail.com", "password"=>"[FILTERED]", "c_password"=>"[FILTERED]", "c_name"=>"FixNix", "location"=>"Chennai", "m_number"=>"9566735440", "isms"=>"Yes", "no_empl"=>"1", "date_started(1i)"=>"2013", "date_started(2i)"=>"5", "date_started(3i)"=>"9", "modules_list"=>"1"}, "commit"=>"Save Companies"}
  [1m[35m (0.1ms)[0m  BEGIN
  [1m[36mSQL (0.3ms)[0m  [1mINSERT INTO `companies` (`c_name`, `c_password`, `created_at`, `date_started`, `email`, `f_name`, `isms`, `l_name`, `location`, `m_number`, `modules_list`, `no_empl`, `password`, `updated_at`) VALUES (NULL, NULL, '2013-05-09 05:54:02', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2013-05-09 05:54:02')[0m
  [1m[35m (42.6ms)[0m  COMMIT
  [1m[36m (0.1ms)[0m  [1mBEGIN[0m
  [1m[35m (0.1ms)[0m  COMMIT
Redirected to companies/create
Completed 302 Found in 48ms (ActiveRecord: 43.2ms)
Connecting to database specified by database.yml

我的控制器代码:

class CompaniesController < ApplicationController
  def new
    @companies = Companies.new 
  end

  def create 
    @companies = Companies.create(params[:id])
    if @companies.save 
        redirect_to 'companies/create'
    end
  end
end

我的表格看起来:

<%= form_for :companies, :url => {:action => "create"} , :method => "post" do |f| %>
Enter your Company Details :
<br />
<br />
<%= label_tag(:f_name, "First Name:") %>
<%= f.text_field(:f_name) %>
<br />
<br />
<%= label_tag(:l_name, "Last Name:") %>
<%= f.text_field(:l_name) %>
<br />
<br />
<%= label_tag(:email , "Email:") %>
<%= f.email_field(:email) %>
<br />
<br />
<%= label_tag(:password , "Password") %>
<%= f.password_field(:password) %>
<br />
<br />
<%= label_tag(:c_password , "Confirm Password") %>
<%= f.password_field(:c_password) %>
<br />
<br />
<%= label_tag(:c_name , "Company Name:") %>
<%= f.text_field(:c_name) %>
<br />
<br />
<%= label_tag(:location , "Location:") %>
<%= f.text_field(:location )%>
<br />
<br />
<%= label_tag(:m_number , "Mobile number") %>
<%= f.telephone_field(:m_number) %>
<br />
<br />
Do You have ISMS implemented ?
<%= f.radio_button(:isms , "Yes" )%>
<%= f.radio_button(:isms , "No") %>
<br />
<br />
<%= label_tag(:no_empl , "No of Employees") %>
<%= f.select(:no_empl ,options_for_select([['> 10',1],['< 10',2],['<100',3]])) %>
<br />
<br />
<%= label_tag(:date_started , "When do you start your organization:")%>

<%= f.date_select(:date_started) %>

<br />
<br />
<%= label_tag (:modules_list) %>
<%= f.select(:modules_list , options_for_select([['Audit Management',1],['Risk Management',2],['Policy Management',3]])) %>
<br />
<br />
<%= f.submit %>


<%end %>
4

1 回答 1

0

我注意到您的代码有两件事有问题。

首先routes.rb,在您的文件中看起来您没有:as =>正确使用。在命名不需要包含的路线时_path,rails 会自动添加它。这是文档

您的代码如下:

match 'companies/create' => 'companies#create' , :as => "create_companies_path" , :via => "post"

它应该是这样的:

match 'companies/create' => 'companies#create' , :as => :create_companies , :via => :post

其次,您redirect_to在控制器中使用不当。要使重定向正常工作,您需要提供完全限定的 URL。Rails 有一个从*_path. 在你的情况下,我会使用这样的东西:

redirect_to create_companies_path

以下是您可以使用的更多示例redirect_to

redirect_to :action => "show", :id => 5
redirect_to post
redirect_to "http://www.rubyonrails.org"
redirect_to "/images/screenshot.jpg"
redirect_to articles_url
于 2013-05-09T06:25:23.813 回答