我新形式的新形式的外观和感觉(放入一些表格,css等等),现在我的"提交"按钮不起作用。它没有创建新记录,也没有执行任何验证回调...我想知道是否有人可以帮助我?这是终端的输出:
Started GET
"/opportunities/new?utf8=%E2%9C%93&authenticity_token=e31DA70sbl%2B3%2FJCeoTcxCTWncLcVs6R6FvR0ZU6vSmA%3D&opportunity%5Bdepartment%5D=DHS&opportunity%5Bagency%5D=asdf&opportunity%5Bprogram_name%5D=fdas&opportunity%5Bstage%5D=Assessment&opportunity%5Bcapture_manager%5D=Sherry+Hwang&opportunity%5Bprogram_description%5D=asdfadsf&opportunity%5Bnew_or_recompete%5D=Re-Compete&opportunity%5Bincumbent%5D=Adsf&opportunity%5Bcurent_contract_vehicle%5D=fdas&opportunity%5Bnew_contract_vehicle%5D=fdas&opportunity%5Bsb_set_aside%5D=Yes&opportunity%5Bprime_or_sub%5D=Prime&opportunity%5Bnaics%5D=234&opportunity%5Brfi_date%281i%29%5D=&opportunity%5Brfi_date%282i%29%5D=&opportunity%5Brfi_date%283i%29%5D=&opportunity%5Brfi_submitted%5D=&opportunity%5Best_rfp_date%281i%29%5D=&opportunity%5Best_rfp_date%282i%29%5D=&opportunity%5Best_rfp_date%283i%29%5D=&opportunity%5Best_full_value%5D=fdsa&opportunity%5Best_workshare%5D=asdf&opportunity%5Bp_win%5D=asdf&opportunity%5Bgovwin_id%5D=adsf&commit=Create+Opportunity"
for 127.0.0.1 at 2014-07-02 10:10:16 -0400
Processing by OpportunitiesController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"e31DA70sbl+3/JCeoTcxCTWncLcVs6R6FvR0ZU6vSmA=",
"opportunity"=>{"department"=>"DHS", "agency"=>"asdf",
"program_name"=>"fdas", "stage"=>"Assessment",
"capture_manager"=>"Sherry Hwang", "program_description"=>"asdfadsf",
"new_or_recompete"=>"Re-Compete", "incumbent"=>"Adsf",
"curent_contract_vehicle"=>"fdas", "new_contract_vehicle"=>"fdas",
"sb_set_aside"=>"Yes", "prime_or_sub"=>"Prime", "naics"=>"234",
"rfi_date(1i)"=>"", "rfi_date(2i)"=>"", "rfi_date(3i)"=>"",
"rfi_submitted"=>"", "est_rfp_date(1i)"=>"", "est_rfp_date(2i)"=>"",
"est_rfp_date(3i)"=>"", "est_full_value"=>"fdsa",
"est_workshare"=>"asdf", "p_win"=>"asdf", "govwin_id"=>"adsf"},
"commit"=>"Create Opportunity"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 9]]
User Load (0.2ms) SELECT "users".* FROM "users"
Rendered opportunities/_form.html.erb (7.4ms)
Rendered opportunities/new.html.erb within layouts/application (8.1ms)
Completed 200 OK in 53ms (Views: 49.9ms | ActiveRecord: 0.4ms)
这是我的机会控制器:
class OpportunitiesController< ApplicationController的 before_action:set_opportunity,only:[:show,:edit,:update,:destroy] before_action:authenticate helper_method:sort_column,:sort_direction
def index
@opportunities = Opportunity.where.not(stage: 'Retired').order(sort_column + " " + sort_direction)
respond_to do |format|
format.html
format.csv {send_data @opportunities.to_csv}
#format.xls {send_data @opportunities.to_csv(col_sep: "\t")}
end
end
def show
@opportunity = Opportunity.find(params[:id])
#render json: @opportunity
end
def new
@opportunity = Opportunity.new
end
def edit
end
def create
@opportunity = Opportunity.new(opportunity_params)
@opportunity.created_by = current_user.full_name
respond_to do |format|
if @opportunity.save
@opportunity.created_by = current_user.full_name
format.html { redirect_to @opportunity, notice: 'Opportunity was successfully created.' }
format.json { render :show, status: :created, location: @opportunity }
else
format.html { render :new }
format.json { render json: @opportunity.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @opportunity.update(opportunity_params)
format.html { redirect_to @opportunity, notice: 'Opportunity was successfully updated.' }
format.json { render :show, status: :ok, location: @opportunity }
else
format.html { render :edit }
format.json { render json: @opportunity.errors, status: :unprocessable_entity }
end
end
end
def destroy
@opportunity.destroy
respond_to do |format|
format.html { redirect_to opportunities_url, notice: 'Opportunity was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_opportunity
@opportunity = Opportunity.find(params[:id])
end
def opportunity_params
params.require(:opportunity).permit(:department, :created_by, :capture_manager, :stage, :agency, :program_name, :program_description, :new_or_recompete, :incumbent, :curent_contract_vehicle, :new_contract_vehicle, :sb_set_aside, :prime_or_sub, :naics, :rfi_date, :rfi_submitted, :est_rfp_date, :est_full_value, :est_workshare, :p_win, :derated_sales, :govwin_id)
end
private
def sort_column
Opportunity.column_names.include?(params[:sort]) ? params[:sort] : "department"
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction]: "asc"
end
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>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>
</table>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
我的路线档案:
Rails.application.routes.draw做
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
答案 0 :(得分:0)
首先,您的提交按钮在您的视图中,请发布。 :)
其次,您正在使用通常位于HTTP GET
的参数POST
。您是否因某种原因意外地在表单中指定了method: :get
?