我有一個機會模型。當我在我的新表單視圖中點擊我的「創建機會」按鈕時,我的終端說我做了一個「GET」請求。此外,單擊它後,它不會運行任何驗證腳本,也不會創建新記錄。我用「回扣路線」,看到我的new_opportunite路線是一個GET請求:更改GET到POST Ruby on Rails
new_opportunity GET /opportunities/new(.:format)機會#新
有誰知道我可以改變這條路線,使它是一個POST?
謝謝!
耙路線:
Prefix Verb URI Pattern Controller#Action
opportunities GET /opportunities(.:format) opportunities#index
POST /opportunities(.:format) opportunities#create
new_opportunity GET /opportunities/new(.:format) opportunities#new
edit_opportunity GET /opportunities/:id/edit(.:format) opportunities#edit
opportunity GET /opportunities/:id(.:format) opportunities#show
PATCH /opportunities/:id(.:format) opportunities#update
PUT /opportunities/:id(.:format) opportunities#update
DELETE /opportunities/:id(.:format) opportunities#destroy
路線文件:
Rails.application.routes.draw do
resources :test_users
get 'profile/my_profile'
get "log_out" => "sessions#destroy", :as => "log_out"
get "log_in" => "sessions#new", :as => "log_in"
get "sign_up" => "users#new", :as => "sign_up"
root :to => "sessions#new"
get 'view_submitted/submitted'
get 'view_action_list/seven'
get 'show_number/thirty'
get 'show_number/sixty'
get 'show_number/year'
get 'view_retired/retired'
resources :users
resource :sessions
get 'report/report_page'
resources :opportunities do
resources :activities
resources :updates
resources :contacts
resources :links
end
我的表格:
<%= form_for(@opportunity) do |f| %>
<% if @opportunity.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@opportunity.errors.count, "error") %> prohibited this opportunity from being saved:</h2>
<ul>
<% @opportunity.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<table id="new_opp_form" style="width: 450px; background-color: white; border-style: none; border:1px orange;">
<tr style="background-color: white">
<td>Department</td>
<td><%= f.select :department, [[],['DHS', 'DHS'], ['DOS', 'DOS'], ['FDIC', 'FDIC'], ['HUD', 'HUD'], ['SEC', 'SEC'], ['VA', 'VA']] %></td>
</tr>
<tr style="background-color: white">
<td>Agency</td>
<td><%= f.text_field :agency %></td>
</tr>
<tr style="background-color: white">
<td>Program Name</td>
<td><%= f.text_field :program_name %></td>
</tr>
<tr style="background-color: white">
<td>Stage</td>
<td><%= f.select :stage, [[],['Assessment', 'Assessment'], ['Pre-Proposal', 'Pre-Proposal'], ['Proposal', 'Proposal'], ['Subitted', 'Submitted'],['Retired', 'Retired']] %></td>
</tr>
<tr style="background-color: white">
<td>Capture Manager</td>
<td><%= f.collection_select(:capture_manager, User.all, :full_name,:full_name,{:prompt => true}) %></td>
</tr>
<tr style="background-color: white">
<td>Program Description</td>
<td><%= f.text_area :program_description %></td>
</tr>
<tr style="background-color: white">
<td>New or Re-recompete</td>
<td><%= f.select :new_or_recompete, [[],['New', 'New'], ['Re-Compete', 'Re-Compete']] %></td>
</tr>
<tr style="background-color: white">
<td>Incumbent</td>
<td><%= f.text_field :incumbent %></td>
</tr>
<tr style="background-color: white">
<td>Current Contract Vehicle</td>
<td><%= f.text_field :curent_contract_vehicle %></td>
</tr>
<tr style="background-color: white">
<td>New Contract Vehicle</td>
<td><%= f.text_field :new_contract_vehicle %></td>
</tr>
<tr style="background-color: white">
<td>Small Business Set Aside?</td>
<td><%= f.select :sb_set_aside, [[],['Yes', 'Yes'], ['No', 'No']] %></td>
</tr>
<tr style="background-color: white">
<td>Prime or Sub</td>
<td><%= f.select :prime_or_sub, [[],['Prime', 'Prime'], ['Sub', 'Sub']] %></td>
</tr>
<tr style="background-color: white">
<td>NAICS</td>
<td><%= f.text_field :naics %></td>
</tr>
<tr style="background-color: white">
<td>RFI Date</td>
<td><%= f.date_select :rfi_date, {:include_blank => true, :default => nil} %></td>
</tr>
<tr style="background-color: white">
<td>RFI Submitted?</td>
<td><%= f.select :rfi_submitted, [[],['Yes', 'Yes'], ['No', 'No']] %></td>
</tr>
<tr style="background-color: white">
<td>Est. RFP Date</td>
<td><%= f.date_select :est_rfp_date, {:include_blank => true, :default => nil} %></td>
</tr>
<tr style="background-color: white">
<td>Est. Full Value</td>
<td><%= f.text_field :est_full_value%></td>
</tr>
<tr style="background-color: white">
<td>Est. Workshare (%)</td>
<td><%= f.text_field :est_workshare %></td>
</tr>
<tr style="background-color: white">
<td>P(win) %</td>
<td><%= f.text_field :p_win %></td>
</tr>
<tr style="background-color: white">
<td>Govwin ID</td>
<td> <%= f.text_field :govwin_id %></td>
</tr>
</table>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
問題不在您的路線。 – zishe