param is missing or the value is empty: incident_datum - ruby-on-rails

I'm new to ruby on rails and I'm having trouble with importing a csv file with data to db. I have been looking around but most of the similar questions on here did not solve this issue.
Problem: param is missing or the value is empty: incident_datum
I understand that this issue is caused by the action controller due to the params.require( but removing it doesn't help because the csv file just gets temporarily uploaded but no data gets extracted from it.
Here are the supporting files =>
Controller:
class IncidentDataController < ApplicationController
before_action :set_incident_datum, only: [:show, :edit, :update, :destroy]
# GET /incident_data
# GET /incident_data.json
def index
#incident_data = IncidentDatum.all
#incident_data_first_20 = IncidentDatum.first(20)
end
def import
IncidentDatum.import(params[:file])
if #IncidentDatum.save
# after import, redirect and let us know the method worked!
redirect_to root_url, notice: "Incident Data Imported!"
else
render :new
end
end
# GET /incident_data/1
# GET /incident_data/1.json
def show
#distinct_number = IncidentDatum.distinct.pluck(:number).sort
end
# GET /incident_data/new
def new
#incident_datum = IncidentDatum.new
end
# GET /incident_data/1/edit
def edit
end
# POST /incident_data
# POST /incident_data.json
def create
#incident_datum = IncidentDatum.new(incident_datum_params)
respond_to do |format|
if #incident_datum.save
format.html { redirect_to #incident_datum, notice: 'Incident datum was successfully created.' }
format.json { render :show, status: :created, location: #incident_datum }
else
format.html { render :new }
format.json { render json: #incident_datum.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /incident_data/1
# PATCH/PUT /incident_data/1.json
def update
respond_to do |format|
if #incident_datum.update(incident_datum_params)
format.html { redirect_to #incident_datum, notice: 'Incident datum was successfully updated.' }
format.json { render :show, status: :ok, location: #incident_datum }
else
format.html { render :edit }
format.json { render json: #incident_datum.errors, status: :unprocessable_entity }
end
end
end
# DELETE /incident_data/1
# DELETE /incident_data/1.json
def destroy
#incident_datum.destroy
respond_to do |format|
format.html { redirect_to incident_data_url, notice: 'Incident datum was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_incident_datum
#incident_datum = IncidentDatum.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def incident_datum_params
params.require(:incident_datum).permit(
:number,
:priority,
:state,
:description,
:short_description1,
:ticket_type,
:task_type,
:opened,
:closed,
:initial_contact,
:configuration_item,
:environment,
:assignment_group,
:reassignment_count,
:department,
:name,
:problem,
:short_description2)
#MG what to do with '.require(:incident_datum)' after params?
end
end
Import:
<div id="import" class="well" style="display:inline-block;width:100%">
<h3 style="margin-top:0px;">Import Data</h3>
<div id="" style="float:left; flex:1;">
<%= form_tag incident_data_path, multipart: true do %>
<%= file_field_tag :file, :style=>'width: 600px;' %>
</div>
<div style="float:right; flex:1;">
<%= submit_tag "Import CSV" %>
</div>
<% end %>
</div>
<a class="btn btn-info" href="/incident_data/">Incident Data</a>
Index.html.erb
<p id="notice"><%= notice %></p>
<h1 style="float:left;">Incident Data</h1><br />
<div class="btn btn-info" style="float:right;">
<%= link_to 'New Incident Datum', new_incident_datum_path%>
</div><br /><br /><br />
<div style="overflow-y:auto;height:600px;">
<%= flash[:notice] %> <!-- Why was this commented out? </th-->
<table class="table table-striped">
<thead>
<tr>
<th>Number</th>
<th>Priority</th>
<th>State</th>
<th>Description</th>
<th>Short description1</th> <!-- Why was this commented out? </th-->
<th>Ticket type</th>
<th>Task type</th>
<th style="display:none">Opened</th>
<th style="display:none">Closed</th>
<th style="display:none">Initial contact</th>
<th>Configuration item</th>
<th>Environment</th>
<th>Assignment group</th>
<th>Reassignment count</th>
<th>Department</th>
<th>Name</th>
<th>Problem</th>
<th>Short description2</th> <!-- Why was this commented out? </th-->
<th colspan="3"></th>
</tr>
</thead>
<!----------------------------------------------------------------------------
[] BREADCRUMS - SHOWS WHERE WE ARE IN THE PAGE
[] PAGEINATOR - GOOGLE THING THAT ALLOWS YOU TO CHOOSE BETWEEN MULTIPLE PAGES //look on main_page.html
----------------------------------------------------------------------------->
<tbody id="descList">
<% #incident_data_first_20.each do |incident_datum| %>
<tr>
<td><%= incident_datum.number %></td>
<td><%= incident_datum.priority %></td>
<td><%= incident_datum.state %></td>
<td data-toggle="modal" data-target="#descModal"><%= incident_datum.short_description1 %></td>
<td><%= incident_datum.ticket_type %></td>
<td><%= incident_datum.task_type %></td>
<td style="display:none"><%= incident_datum.opened %></td>
<td style="display:none"><%= incident_datum.closed %></td>
<td style="display:none"><%= incident_datum.initial_contact %></td>
<td><%= incident_datum.configuration_item %></td>
<td><%= incident_datum.environment %></td>
<td><%= incident_datum.assignment_group %></td>
<td><%= incident_datum.reassignment_count %></td>
<td><%= incident_datum.department %></td>
<td><%= incident_datum.name %></td>
<td><%= incident_datum.problem %></td>
<td style="display:none"><%= incident_datum.description %></td>
<td style="display:none"><%= incident_datum.short_description2 %></td>
<td><%= link_to 'Show', incident_datum %></td>
<td><%= link_to 'Edit', edit_incident_datum_path(incident_datum) %></td>
<td><%= link_to 'Destroy', incident_datum, method: :destroy, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<%= render partial: "modal", locals: {zone: #zone} %>
routes:
Rails.application.routes.draw do
#resources :incident_data
# INDEX
#root to: 'analysis#main_page'
# Database Tables
resources :incident_data do
collection { post :import }
end
root to: 'analysis#main_page' #MG
# ADDITIONAL PAGES
get 'analysis/main_page'
get 'analysis/new_tile'
get 'analysis/ticket_identification'
get 'analysis/detailed_view'
get 'analysis/import_data'
get 'analysis/test'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
Console:
Processing by IncidentDataController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"lBXX210GVPazui46U8rATpzrXCMJw8DAqb7Hc3WWK2uTU3WGojClRU7+ZKkakCjUblweOV7UpM+FiIvRSNzSng==", "file"=>#<ActionDispatch::Http::UploadedFile:0x00000002829388 #tempfile=#<Tempfile:/tmp/RackMultipart20180110-11292-jzqi2l.csv>, #original_filename="incident_datum.csv", #content_type="application/vnd.ms-excel", #headers="Content-Disposition: form-data; name=\"file\"; filename=\"incident_datum.csv\"\r\nContent-Type: application/vnd.ms-excel\r\n">, "commit"=>"Import CSV"}
Completed 400 Bad Request in 2ms (ActiveRecord: 0.0ms)
ActionController::ParameterMissing (param is missing or the value is empty: incident_datum):
app/controllers/incident_data_controller.rb:84:in `incident_datum_params'
app/controllers/incident_data_controller.rb:39:in `create'
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2018-01-10 14:20:33 +0000 ===
- Goodbye!
Exiting
Thank you!

I think your problem is your Form (if you want keep rails convention), you have to create a IncidentDatum element and create a form for this element like:
<%= form_for #incident_data , multipart: true do %>
...
With this you create a form like incident_datum : { file: .... }
This format you spec in the def incident_datum_params method
params.require(:incident_datum).permit( :number , ....
Also you need to add file to permit
params.require(:incident_datum).permit( :number , :file , ....
You can see the format of your post in your console browser network tab and also in the log you post in the question:
Processing by IncidentDataController#create as HTML Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"lBXX210GVPazui46U8rATpzrXCMJw8DAqb7Hc3WWK2uTU3WGojClRU7+ZKkakCjUblweOV7UpM+FiIvRSNzSng==",
"file"=>#,
#original_filename="incident_datum.csv",
#content_type="application/vnd.ms-excel",
#headers="Content-Disposition: form-data; name=\"file\";
filename=\"incident_datum.csv\"\r\nContent-Type:
application/vnd.ms-excel\r\n">, "commit"=>"Import CSV"} Completed 400
Bad Request in 2ms (ActiveRecord: 0.0ms)
You can see file direct in the params ( no inside incident_data incident_data: { fiel: .... } )

Related

Running into undefined method from model class in view

I have a method called calculation_of_total_cost in model Tippy
It's running into problems being called in index.html.erb via tippies views directory.
This is the error I receive: undefined method*' for nil:NilClass`
I have googled it, and now understand that it is the result of the one of the variables being nil.
How do I resolve this, i.e, how do I make the method work in index.html.erb? This is index view that I am calling it from, so I need an instance method, not class, right?
Also, addendum: this same method works fine in show.html.erb
show.html.erb
<br/><br/>
<h1 class="text-center">Your Total Cost</h1>
<br/><br />
<table class="table table-striped">
<tr>
<td>
Cost of Your Meal:
</td>
<td>
<%= humanized_money_with_symbol #tippy.cost %>
</td>
</tr>
<tr>
<td>
Tip You Picked:
</td>
<td>
<%= number_to_percentage(#tippy.tip * 100, format: "%n%", precision: 0) %>
</td>
</tr>
<tr>
<td>
The Total Cost:
</td>
<td>
<%= humanized_money_with_symbol #tippy.calculation_of_total_cost %>
</td>
</tr>
</table>
<%= link_to 'New Tippy', new_tippy_path %>
<%= link_to "Index", tippies_path %>
Here is the Tippy model:
class Tippy < ApplicationRecord
validates :tip, presence: true
validates :cost, presence: true
#monetize :tip_cents
monetize :cost_cents, :numericality => {:greater_than => 0}
TIP_CHOICES = { "10%" => ".10", "20%" => ".20", "30%" => ".30", "40%" => ".40", "50%" => ".50",
"60%" => ".60", "70%" => ".70", "80%" => ".80", "90%" => ".90" }
def calculation_of_total_cost
cost + (tip * cost)
end
end
Here is the index.html.erb file
<p id="notice"><%= notice %></p>
<h1>Tippies</h1>
<table>
<thead>
<tr>
<th>Tip</th>
<th>Cost</th>
<th>Total</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% #tippies.each do |tippy| %>
<tr>
<td><%= tippy.tip %></td>
<td><%= tippy.cost %></td>
<td><%= tippy.calculation_of_total_cost %></td>
<td><%= link_to 'Show', tippy %></td>
<td><%= link_to 'Edit', edit_tippy_path(tippy) %></td>
<td><%= link_to 'Destroy', tippy, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Tippy', new_tippy_path %>
Tippy Controller
class TippiesController < ApplicationController
#before_action :set_tippy, only: [:show, :edit, :update, :destroy]
# GET /tippies
# GET /tippies.json
def index
#tippies = Tippy.all
end
# GET /tippies/1
# GET /tippies/1.json
def show
##calculation_of_total_cost
end
# GET /tippies/new
def new
#tippy = Tippy.new
end
# GET /tippies/1/edit
def edit
end
# POST /tippies
# POST /tippies.json
def create
#tippy = Tippy.new(tippy_params)
respond_to do |format|
if #tippy.save
format.html { redirect_to #tippy, notice: 'Tippy was successfully created.' }
format.json { render :show, status: :created, location: #tippy }
else
format.html { render :new }
format.json { render json: #tippy.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /tippies/1
# PATCH/PUT /tippies/1.json
def update
respond_to do |format|
if #tippy.update(tippy_params)
format.html { redirect_to #tippy, notice: 'Tippy was successfully updated.' }
format.json { render :show, status: :ok, location: #tippy }
else
format.html { render :edit }
format.json { render json: #tippy.errors, status: :unprocessable_entity }
end
end
end
# DELETE /tippies/1
# DELETE /tippies/1.json
def destroy
#tippy.destroy
respond_to do |format|
format.html { redirect_to tippies_url, notice: 'Tippy was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_tippy
#tippy = Tippy.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def tippy_params
params.require(:tippy).permit(:tip, :cost)
end
end
To solve this problem you need to set a binding.pry or a breakpoint at this line of index.html.erb, so that we can understand in the loop you are executing why tippy is getting value of nil.
You need to install pry gem.
Please also share the values of #tippies and the details of the other variable in the loop that fails, because tippy=nil.
An alternative for pry is just printing the value of the variable in the log with puts tippy.calculation_of_total_cost.
Right now I am guess is that #tippies which includes all #tippy in your tippies table, could have one field that has calculation of total cost = nil. To verifiy this you should check with the debug the value of tippy and of tippy.calculation_of_total_cost in the index.html.erb view.
<% #tippies.each do |tippy| %>
<tr>
<% binding.pry %>
<td><%= tippy.tip %></td>
<td><%= tippy.cost %></td>
<td><%= tippy.calculation_of_total_cost %></td>
<td><%= link_to 'Show', tippy %></td>
<td><%= link_to 'Edit', edit_tippy_path(tippy) %></td>
<td><%= link_to 'Destroy', tippy, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
also it is a good idea to inspect show.html.erb as there it is working.
def calculation_of_total_cost
cost + (tip * cost)
end

Prepend table element to list of data using Ajax and Rails

I am trying to prepend a recently created post to a list without having to refresh the browser. I am wondering how this can be done with table elements.
index.html.erb
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Card image</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody id="content">
<%= render #suggested_invites %>
</tbody>
</table>
_suggested_invite.html.erb
<% #suggested_invites.each do |suggested_invite| %>
<tr style="background-color:<%= suggested_invite.color %>">
<td style="color:white"><%= suggested_invite.name %></td>
<td><img src="<%= suggested_invite.card_image %>" class="img-fluid" id="card_image" alt="Responsive image"></td>
<td><%= link_to 'Edit', edit_suggested_invite_path(suggested_invite), :class => 'action_buttons' %></td>
<td><%= link_to 'De-Activate', suggested_invite, method: :delete, :class => 'action_buttons', data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
suggested_invites_controller.rb
def create
#suggested_invite = SuggestedInvite.new(suggested_invite_params)
respond_to do |format|
if #suggested_invite.save
format.html { redirect_to #suggested_invite, notice: 'Suggested invite was successfully created.' }
format.json { render :show, status: :created, location: #suggested_invite }
format.js
else
format.html { render :new }
format.json { render json: #suggested_invite.errors, status: :unprocessable_entity }
format.js
end
end
end
create.js.erb
$("#mynewsuggestedinvite").modal('hide');
$("#content").prepend('<%= j render #suggested_invite %>');
When I run this code I get a 500 internal server error. I know that it breaks here:
$("#content").prepend('<%= j render #suggested_invite %>');
I have been looking and haven't found any ways of doing this. Any help would be very much appreciated!
To see which error you get, without access to logs you can do this:
begin
$("#content").prepend('<%= j render #suggested_invite %>');
rescue Error => e
<%= raw e.backtrace %>
end
Then check the server response when trying to create

ArgumentError in Shakes#index , nil is not a valid asset source

Hi guys when iam trying to pull image using image tag its giving nil is not a valid asset source ive image file in my assests , strangely this problem is only occuring when iam trying use decorator pattern else without it image is being properly displaye ,Iam fairly new to this can any of the experts shred some light what am i doing wrong ?
Thanks
require 'shake_decorator'
class ShakesController < ApplicationController
before_action :set_shake, only: [:show, :edit, :update, :destroy]
# GET /shakes
# GET /shakes.json
def index
#shakes = Shake.all
end
# GET /shakes/1
# GET /shakes/1.json
def show
end
# GET /shakes/new
def new
#shake = Shake.new
end
# GET /shakes/1/edit
def edit
end
# POST /shakes
# POST /shakes.json
def create
#shake = Shake.new()
#shake.Name=params[:shake][:Name]
#shake.Cost=params[:shake][:Cost]
#shake.Calories=params[:shake][:Calories]
# create an instance/object of a BasicCar
myShake=BasicShake.new(#shake.Cost,#shake.Calories)
#add the extra features to the new car
if params[:shake][:caramel].to_s.length > 0 then
myShake = CaramelDecorator.new(myShake)
end
if params[:shake][:pbutter].to_s.length > 0 then
myShake = PeanutbutterDecorator.new(myShake)
end
if params[:shake][:cream].to_s.length > 0 then
myShake = CreamDecorator.new(myShake)
end
#populate the cost and the description details
#shake.Cost = myShake.cost
#shake.description = myShake.details
#retrieve the instance/object of the MyLogger class
respond_to do |format|
if #shake.save
format.html { redirect_to #shake, notice: 'Shake was successfully created.' }
format.json { render :show, status: :created, location: #shake }
else
format.html { render :new }
format.json { render json: #shake.errors, status: :unprocessable_entity }
end
end
end
# DELETE /shakes/1
# DELETE /shakes/1.json
def destroy
#shake.destroy
respond_to do |format|
format.html { redirect_to shakes_url, notice: 'Shake was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_shake
#shake = Shake.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def shake_params
params.require(:shake).permit(:Name, :Cost, :Calories, :image_url)
end
end
<p id="notice"><%= notice %></p>
<h1>Shakes</h1>
<table border="2">
<thead>
<tr>
<th>Name</th>
<th>Cost</th>
<th>Calories</th>
<th>Image url</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% #shakes.each do |shake| %>
<tr>
<td><%= shake.Name %></td>
<td><%= shake.Cost %></td>
<td><%= shake.Calories %></td>
<td><%= image_tag(shake.image_url, :class => 'list_image' ,:style => "height:100px") %></td>
<td><%= link_to 'Show', shake %></td>
<td><%= link_to 'Edit', edit_shake_path(shake) %></td>
<td><%= link_to 'Destroy', shake, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Shake', new_shake_path %>

Why is only part of my code not rendering in view

While I was working trying to code my views, I noticed that my code that was previously rendering on the index view is now only showing the first two lines of code on my local server, and I don't understand why.
Here is my index.html.erb code:
<h1>All Bookmarks</h1>
<%= link_to 'Create a New Bookmark', new_bookmark_path %>
<table>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<div class="row">
<div class="col-md-8">
<tbody>
<% #bookmarks.each do |bookmark| %>
<div class="media">
<div class="media-body">
<h4 class="media-heading">
<tr>
<td><%= link_to bookmark.url, "http://#{bookmark.url}" %></td>
<td><%= link_to 'Show', bookmark %></td>
<td><%= link_to 'Edit', edit_bookmark_path(bookmark) %></td>
<td><%= link_to 'Destroy', bookmark, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
And here is my bookmark controller code:
class BookmarksController < ApplicationController
before_action :set_bookmark, only: [:show, :edit, :update, :destroy]
def index
#bookmarks = Bookmark.all
end
def show
end
def new
#bookmark = Bookmark.new
end
def edit
end
def create
bookmark = Bookmark.where(url: params[:bookmark][:url]).first
#bookmark = bookmark.present? ? bookmark : Bookmark.new(bookmark_params)
if #bookmark.save
#bookmark.users << current_user
Rails.logger.info ">>>>>>>>>>>>> Bookmark: #{#bookmark.inspect}"
topic_names = params[:topic_names].split(' ')
topic_names.each do |topic_name|
name = topic_name.sub(/#/, '')
#bookmark.topics << Topic.find_or_create_by_name(name)
end
respond_to do |format|
format.html { redirect_to #bookmark, notice: 'Bookmark was successfully created.' }
format.json { render action: 'show', status: :created, location: #bookmark }
end
else
respond_to do |format|
format.html { render action: 'new' }
format.json { render json: #bookmark.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if #bookmark.update(bookmark_params)
format.html { redirect_to #bookmark, notice: 'Bookmark was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: #bookmark.errors, status: :unprocessable_entity }
end
end
end
def destroy
#bookmark.destroy
respond_to do |format|
format.html { redirect_to bookmarks_url }
format.json { head :no_content }
end
end
private
def set_bookmark
#bookmark = Bookmark.find(params[:id])
end
def bookmark_params
params.require(:bookmark).permit(:url)
end
end
Any thoughts?
It seems that your html is invalid. You are using div tags in rails loop, which is not being closed. The other thing is that non-table related html tags can be used only inside tags.
This might be the working solution.
<h1>All Bookmarks</h1>
<%= link_to 'Create a New Bookmark', new_bookmark_path %>
<table>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% #bookmarks.each do |bookmark| %>
<tr>
<td><%= link_to bookmark.url, "http://#{bookmark.url}" %></td>
<td><%= link_to 'Show', bookmark %></td>
<td><%= link_to 'Edit', edit_bookmark_path(bookmark) %></td>
<td><%= link_to 'Destroy', bookmark, method: :delete, data: { confirm: 'Are you sure?' } %> </td>
</tr>
<% end %>
</tbody>
</table>
Hope that helps.

Ruby on Rails Submit button not working

I the look and feel of my new form for a new Opportunity (put in some tables, css, etc...) and now my "submit" button won't work. It doesn't create a new record nor does it perform any of the validation callbacks... I was wondering if anyone could help me? Here is the output from the terminal:
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)
And here is my Opportunity controller:
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
My view:
<%= 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 %>
My routes file:
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
First, your submit button is in your view, please post that. :)
Second, you're doing an HTTP GET with the parameters that would typically be in a POST. Have you specified your method: :get in the form for some reason accidentally?

Resources