ActionController::ParameterMissing (param is missing or the value is empty: bid) - ruby-on-rails

When I try to customize my bid_params to add a parameter to the database, my strong parameters are not working for some reason. I need to be able to have the current_user passed into the database on the creation of a bid. This object is nested in a has_many belongs_to relationship with Auctions. Here is my controller:
class BidsController < ApplicationController
def index
#auction = Auction.find(params[:auction_id])
#bids = #auction.bids
end
def new
#auction = Auction.find(params[:auction_id])
#bid = #auction.bids.build
end
def create
#auction = Auction.find(params[:auction_id])
#bid = #auction.bids.create(bid_params)
if #bid.save
flash[:success] = "Bid has been successfully placed."
redirect_to #auction
else
flash[:error] = #bid.errors.full_messages.join('. ')
render 'new'
end
end
def destroy
#auction = Auction.find(params[:auction_id])
#bid = #auction.bids.find
#bid.destroy
flash[:notice] = "Successfully destroyed Bid."
redirect_to auction_url(#bid.article_id)
end
private
def bid_params
params.require(:bid).permit(:auction_id).merge(bidder: current_user)
end
end
and Stack Trace:
Started POST "/auctions/2/bids" for 127.0.0.1 at 2014-12-06 08:54:35 -0600
Processing by BidsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"6x4hV8y323a10kaJN5Rubj1z3uhUrSDQrD6aoaWCUhk=", "commit"=>"Create Bid", "auction_id"=>"2"}
Auction Load (0.1ms) SELECT "auctions".* FROM "auctions" WHERE "auctions"."id" = ? LIMIT 1 [["id", 2]]
Completed 400 Bad Request in 2ms
ActionController::ParameterMissing (param is missing or the value is empty: bid)
New Form:
<h1>Create a New Bid</h1>
<%= form_for ([#auction, #bid]) do |f|%>
<p>
<%= f.submit %>
</p>
<%end%>
Thanks!

Look at parameters that controller received:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"6x4hV8y323a10kaJN5Rubj1z3uhUrSDQrD6aoaWCUhk=", "commit"=>"Create Bid", "auction_id"=>"2"}
And then you try to permit these params:
def bid_params
params.require(:bid).permit(:auction_id).merge(bidder: current_user)
end
And error was thrown in this operation: params.require(:bid) as this method suppose your params looks like:
{ ..., "bid" => { "auction_id" => "2" } }
Hence you may change your view/js that sends params or change def bid_params implementation to:
def bid_params
params.permit(:auction_id).merge(bidder: current_user)
end

Related

How to give ID to other controller: no implicit conversion of Symbol into Integer error

I want to give an id of "paper model" to "schedules model" and create a note_id.
However an error message "no implicit conversion of Symbol into Integer" shows.
Can someone help me to solve this problem?
papers/index.html.erb
<%= link_to "Go to Schedule", new_schedule_path(id: paper.id) %>
routes.rb
get '/schedules/new/:id', to: 'schedules#new', as: :schedules_new
schedules_controller
class ActionsController < ApplicationController
before_action :authenticate_user!
before_action :set_schedule, only: [:edit, :update, :destroy]
def new
#schedule = Schedule.new
end
def create
#schedule = Schedule.new(schedule_params)
#schedule.user_id = current_user.id
#schedule.note_id = params[:id]
if #schedule.save
redirect_to schedules_path, notice: "A schedule was saved!"
end
end
def index
#schedules = Schedule.all
end
def update
end
def delete
end
Private
def schedule_params
params.require(:schedule).permit(:note_id, :user_id, :params[:id])
end
def set_schedule
#schedule = Schedule.find(params[:id])
end
end
params
=> "31", "controller"=>"schedules", "action"=>"new"} permitted: false>
You are not even using shedule_params values, as you override them afterwards ......
Then you could create empty Schedule object and then assign values ...
def create
#schedule = Schedule.new
#schedule.user_id = current_user.id
#schedule.note_id = params[:id]
if #schedule.save
redirect_to schedules_path, notice: "A schedule was saved!"
end
end
Or if I am correct with your relations, it could be also
def create
#schedule = current_user.schedules.new
#schedule.note_id = params[:id]
if #schedule.save
redirect_to schedules_path, notice: "A schedule was saved!"
end
end
I could solve this problem as follow.
Controller:
def new
#schedule = Schedule.new
#schedule.note_id = params[:id]
end
def create
#schedule = Schedule.new(schedule_params)
#schedule.user_id = current_user.id
if #schedule.save
redirect_to schedules_path, notice: "A schedule was saved!"
else
render 'new'
end
end
.
.
.
Private
def schedule_params
params.require(:schedule).permit(:note_id, :user_id)
end
Add into View
<%= f.hidden_field :id, :value => #schedule.note_id %>

Find a record using form params in rails "couldn't find error"

I am new to rails. I am trying to Find a 'Category' record using a value submitted in a form field. Since I use Find by params[:id] for url parameters all the time, I thought it would work for form parameters.
This is my error
Couldn't find Category with 'id'=
on this line:
#category = Category.find(params[:category_id])
Here is my code
posts_controller.rb
def delete
#post = Post.find(params[:id])
#category = Category.find(#post.category_id)
#post_archive = PostArchive.new
end
def destroy
#post = Post.find(params[:id])
*#category = Category.find(params[:category_id])* <--the error hits here
#old_id = params[:post_id]
#author_id = params[:author_id]
#followers = Follower.find(post_id: #old_id)
#post_archive = PostArchive.new
PostArchive.create!(post_id: #old_id, author_id: #author_id , removed_by: current_user.id,
category_id: #category.id,
post_created_at: #post.created_at )
#post.destroy
#followers.each do |follower|
ProjectMailer.post_deletion(current_user, #category, #author_id, follower, #old_id ).deliver
end
#followers.destroy_all
redirect_to posts_path, notice: 'Project Deleted'
end
form
<%= form_for :delete_post, url: post_destroy_path(#post), method: :delete do |f| %>
<%= f.hidden_field :author_id#post.author_id %>
<%= f.hidden_field :category_id, #post.category_id %>
<%= f.hidden_field :post_id, value: #post.id %>
Are you sure you want to delete <%=#post.title %>?
<%=f.submit %>
<% end %>
I've tested that I can find the param using Categorgy.find(2) and I've tested that the param is actually showing up in the form (it's a hidden field....so I needed to )
server log:
Processing by PostsController#destroy as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"s2pglEj+LUIvZ8OJ0i/sbb3T8hDTcFrqdV0rJqa3c/pihtrMez4S5A8bK3NmoQ/BleKrMRuMTUhZvCwl+00jeQ==", "delete_post"=>{"author_id"=>"21", "category_id"=>"2", "post_id"=>"417"}, "commit"=>"Delete Post", "id"=>"417"}
As you can see from your params, category_id is inside delete_post
Parameters: {"delete_post"=>{"author_id"=>"21", "category_id"=>"2", "post_id"=>"417"}, "commit"=>"Delete Post", "id"=>"417"}
It should be
#category = Category.find(params[:delete_post][:category_id])
def destroy
#post = Post.find(params[:id])
*#category = Category.find(params[:category_id])* <--the error hits here
# change to
# *#category = Category.find(params[:delete_post][:category_id])*
#old_id = params[:post_id]
#author_id = params[:author_id]
#followers = Follower.find(post_id: #old_id)
#post_archive = PostArchive.new
PostArchive.create!(post_id: #old_id, author_id: #author_id , removed_by: current_user.id,
category_id: #category.id,
post_created_at: #post.created_at )
#post.destroy
#followers.each do |follower|
ProjectMailer.post_deletion(current_user, #category, #author_id, follower, #old_id ).deliver
end
#followers.destroy_all
redirect_to posts_path, notice: 'Project Deleted'
end

Issues with update action using acts_as_votable

I'm currently getting the votes to hit the database but I'm now having issues getting the update action to work in my controller. The votes don't record with the update action but do without out it. However, I then get a missing template error for Pits#update. Any help is appreciated. Thanks.
Terminal Error
Started PUT "/pits/3" for 127.0.0.1 at 2014-08-21 11:38:25 -0500
Processing by PitsController#update as JS
Parameters: {"id"=>"3"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 4 ORDER BY "users"."id" ASC LIMIT 1
Pit Load (0.2ms) SELECT "pits".* FROM "pits" WHERE "pits"."user_id" = ? AND "pits"."id" = ? LIMIT 1 [["user_id", 4], ["id", 3]]
Completed 404 Not Found in 64ms
ActiveRecord::RecordNotFound (Couldn't find Pit with 'id'=3 [WHERE "pits"."user_id" = ?]):
app/controllers/pits_controller.rb:37:in `update'
I currently have
Pits Controller
class PitsController < ApplicationController
def new
#pit = Pit.new
end
def index
#pit = Pit.all
#user = User.find_by(params[:id])
#pits = Pit.paginate(:page => params[:page]).order('created_at ASC').group_by { |pit| pit.created_at.strftime("%B %Y") }
end
def create
#user = current_user
#pit = current_user.pits.create(pit_params)
if #pit.save
redirect_to #pit
else
render 'new'
end
end
def show
#pit = Pit.find(params[:id])
end
def edit
end
def update
#user = current_user
#pit = current_user.pits.find(params[:id])
if #pit.update_attributes(pit_params)
redirect_to #pit
end
end
private
def pit_params
params.require(:pit).permit(:topic, :summary, :image, :video_url, :author, :user_id)
end
end
Comments Controller
class CommentsController < ApplicationController
def create
#pit= Pit.find(params[:pit_id])
#comment = #pit.comments.build(comments_params)
#comment.user = current_user
#comment.save
redirect_to pit_path(#pit)
end
def destroy
#pit = Pit.find(params[:pit_id])
#comment = #pit.comments.find(params[:id])
#comment.destroy
redirect_to pit_path(#pit)
end
def upvote
#pit = Pit.find(params[:pit_id])
#comment = #pit.comments.find(params[:comment_id])
#comment.upvote_by current_user
redirect_to pit_path(#pit)
end
def downvote
#pit = Pit.find(params[:pit_id])
#comment = #pit.comments.find(params[:comment_id])
#comment.downvote_from current_user
redirect_to pit_path(#pit)
end
def update
end
def show
end
private
def comments_params
params.require(:comment).permit(:body, :user_id, :votable, :voter, :vote_scope)
end
end
_comment.html.erb
<div class = "well">
<p>
<strong>Comment:</strong>
<%= comment.body %>
<p>posted by: <%= comment.user.name %></p>
<%= link_to "Like", pit_comment_like_path(#pit, comment), method: :put , :remote => true %>
<%= link_to "Dislike", pit_comment_dislike_path(#pit, comment), method: :put, :remote => true %>
</p>
<p>
<%if comment.user == current_user %>
<%= link_to 'Destroy Comment', [#pit, comment],
method: :delete,
data: { confirm: 'Are you sure?' } %>
<% end %>
</p>
</div>
Not sure about everything you have going on here, but I suspect the error has to do with use current_user to find the pit. If the current_user is not the user_id for the pit, it won't find any pit (exactly your error).
Try adjusting to this and it should be able to find the pit propperly.
def update
#pit = Pit.find(pit_params[:id])
if #pit.update_attributes(pit_params)
redirect_to #pit
end

Ruby Adding To Database

I am new in Ruby and I have to finish my school project. I have problem because we make one project in 14 people, everyone has his own part. I have to create new appointment but someone used this before and I cannot use this again (I want to add this simple from form). Please help me because I am stuck now, I don't want change someone's code. I render _form51.html.erb from new51.html.erb. Maybe I can use any simple redirect to create51?;> But I don't know how ;(
EDITED:
NOW SOLVED BUT why app create always empty appointment?
Routes.rb:
ZOZ::Application.routes.draw do
resources :refferals do
collection do
get 'new51'
end
member do
get 'show'
end
end
resources :appointments do
collection do
get 'search' #17
get 'search_result' #17
get 'to_confirm' #17
get 'search_not' #57
get 'search_result_not' #57
get 'add_or_edit_not' #57
get 'searchdate'
get 'searchd'
get 'move'
get 'new51'
post :create51
end
member do
put :confirm #17
put :update_not #57
get 'show51'
end
end
resources :clinics do
collection do
get 'index51'
end
member do
get 'show51s'
end
end
resources :doctors do
collection do
get 'index51a'
get 'index51'
get 'search54'
get 'search_result54'
get 'show_harmonogram'
end
member do
get 'show51s'
get 'show51ss'
end
end
resources :patients do
collection do
get 'select51'
get 'index51'
end
member do
get 'show51s'
get 'show51ss'
end
end
get "welcome/index2"
get "welcome/index"
get 'appointments/create'
get 'appointments/move' => 'appointments#move'
post 'appointments/move' => 'appointments#doctors_list'
get 'appointments/move/:id' => 'appointments#doctor_appointments', as: :doctor_appointments
get 'appointments/change_appointment/:id' => 'appointments#change_appointment', as: :change_appointment
get 'appointments/change_doctor_and_appointment/:id' => 'appointments#change_doctor_and_appointment', as: :change_doctor_and_appointment
get 'appointments/success' => 'appointments#success'
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
root :to => 'welcome#index'
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id))(.:format)'
end
_form51.html.erb:
<%= form_for(#appointment) do |f| %>
<% if #appointment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#appointment.errors.count, "error") %> prohibited this appointment from being saved:</h2>
<ul>
<% #appointment.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :data_godzina_wizyty %><br />
<%=
options = { start_year: 2.year.from_now.year,
end_year: 2013,
include_blank: true,
default: nil }
f.datetime_select :data_godzina_wizyty, options
%>
<!--<input type="text" data-behaviour='datepicker' :data_wizyty > -->
</div>
<div class="field">
<%= f.hidden_field :doctor_id, :value => Doctor.find(session[:current_doctor_id2]).id %>
</div>
<div class="field">
<%= f.hidden_field :patient_id, :value => Patient.find(session[:current_patient_id]).id %>
</div>
<div class="actions">
<%= submit_tag "Utworz wizyte" %>
</div>
<% end %>
New51.html.erb:
<div id="container">
<center>
<h1>Nowa wizyta:</h1>
<p>Sprawdz poprawnosc ponizszych danych a nastepnie uzupelnij formularz.</p>
<h3>Dane lekarza:</h3>
<p>
<strong>Imię lekarza:</strong>
<%= Doctor.find(session[:current_doctor_id2]).imie_lekarza %>
</p>
<p>
<strong>Nazwisko lekarza:</strong>
<%= Doctor.find(session[:current_doctor_id2]).nazwisko_lekarza %>
</p>
<p>
<strong>Specjalizacja lekarza:</strong>
<%= Doctor.find(session[:current_doctor_id2]).specjalizacja %>
</p>
<h3>Dane pacjenta:</h3>
<p>
<strong>Imie:</strong>
<%= Patient.find(session[:current_patient_id]).imie %>
</p>
<p>
<strong>Nazwisko:</strong>
<%= Patient.find(session[:current_patient_id]).nazwisko %>
</p>
<p>
<strong>Pesel:</strong>
<%= Patient.find(session[:current_patient_id]).pesel %>
</p>
<%= render 'form51' %>
<%= link_to 'Wybierz innego lekarza', index51_doctors_path %>
</br>
</center>
</div>
Appointments_Controller:
class AppointmentsController < ApplicationController
before_filter :load_appointment, only: [:show, :update, :edit, :destroy]
before_filter :load_wizard, only: [:new, :edit, :create]
def searchd
end
def move
end
def doctors_list
#doctors = Doctor.where("imie_lekarza like ? or nazwisko_lekarza LIKE ? or specjalizacja LIKE ?", "%#{params[:search]}%", "%#{params[:search]}%", "%#{params[:search]}%")
end
def doctor_appointments
#doctor = Doctor.find(params[:id])
#appointments = #doctor.appointments
end
def change_appointment
#appointment = Appointment.find(params[:id])
end
def change_doctor_and_appointment
#doctors = Doctor.all
#appointment = Appointment.find(params[:id])
end
def success
#notice = flash[:notice]
end
def searchdate
d = params[:date]
data = Date.new(d["(1i)"].to_i, d["(2i)"].to_i, d["(3i)"].to_i)
#appointments = Appointment.scoped
#appointments = #appointments.where(:data_godzina_wizyty => data.beginning_of_day..data.end_of_day)
end
def search_not
end
def search_result_not
#pacjent
#patients = Patient.scoped
#patients = #patients.where(pesel: params[:pesel])
d = params[:date]
if d["(1i)"] != "" and d["(2i)"]. != "" and d["(3i)"] != ""
data = Date.new(d["(1i)"].to_i, d["(2i)"].to_i, d["(3i)"].to_i)
#appointments = #patients.first.appointments.where(:data_godzina_wizyty => data.beginning_of_day..data.end_of_day)
else
#appointments = #patients.first.appointments
end
end
def add_or_edit_not
session['last_search_not'] = request.env["HTTP_REFERER"]
#appointment = Appointment.find(params[:id])
#patient = Patient.find(#appointment.patient_id)
if #appointment.doctor_id != nil
#doctor = Doctor.find(#appointment.doctor_id)
end
if #appointment.refferal_id != nil
#refferal = Refferal.find(#appointment.refferal_id)
end
end
def update_not
#appointment = Appointment.find(params[:id])
#appointment.notatka = params[:notatka]
if #appointment.save
redirect_to session[:last_search_not], notice: 'Notatka zostala zapisana.'
else
redirect_to :back, notice: 'Niestety wystapil blad. Prosze sprubowac pozniej'
end
end
def search
end
def new51
#appointment = Appointment.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: #appointment }
end
end
def create51
#appointment = Appointment.new(params[:patient])
respond_to do |format|
if #appointment.save
format.html { redirect_to #appointment, notice: 'Szczegoy wizyty pomyslnie zmodyfikowane!' }
format.json { render json: #appointment, status: :created, location: #appointment }
else
format.html { render action: "new" }
format.json { render json: #appointment.errors, status: :unprocessable_entity }
end
end
end
def search_result
d = params[:date]
data = Date.new(d["(1i)"].to_i, d["(2i)"].to_i, d["(3i)"].to_i)
#szukanie pacjenta
#patients = Patient.scoped
#patients = #patients.where(pesel: params[:pesel])
if params[:imie] != ""
#patients = #patients.where(imie: params[:imie])
end
if params[:nazwisko] != ""
#patients = #patients.where(nazwisko: params[:nazwisko])
end
#szukanie doctora
opcja = 0
#doctors = Doctor.scoped
if params[:imie_lekarza] != ""
#doctors = #doctors.where(imie_lekarza: params[:imie_lekarza])
opcja = 1
end
if params[:nazwisko_lekarza] != ""
#doctors = #doctors.where(nazwisko_lekarza: params[:nazwisko_lekarza])
opcja = 1
end
#zlaczenie
#patient_appo = #patients.first.appointments.where(:data_godzina_wizyty => data.beginning_of_day..data.end_of_day, potwierdzona: false)
if opcja == 1
#doctors_appo = #doctors.first.appointments.where(:data_godzina_wizyty => data.beginning_of_day..data.end_of_day, potwierdzona: false)
#appointments = #patient_appo & #doctors_appo
else
#appointments = #patient_appo
end
end
def to_confirm
session['last_search'] = request.env["HTTP_REFERER"]
#appointment = Appointment.find(params[:id])
#patient = Patient.find(#appointment.patient_id)
if #appointment.doctor_id != nil
#doctor = Doctor.find(#appointment.doctor_id)
end
if #appointment.refferal_id != nil
#refferal = Refferal.find(#appointment.refferal_id)
end
end
def confirm
#appointment = Appointment.find(params[:id])
#appointment.potwierdzona = true
if #appointment.save
#redirect_to :back, notice: 'Rejestracja zostala pomyslnie potwierdzona.'
redirect_to session[:last_search], notice: 'Rejestracja zostala pomyslnie potwierdzona.'
else
redirect_to :back, notice: 'Niestety wystapil blad. Prosze sprubowac pozniej'
end
end
def index
#appointments = Appointment.all
end
def show
end
def new
#appointment = #wizard.object
#clinics = Clinic.all
#doctors = Doctor.all
end
public
def findDoctorViaClinic( clinic )
return( (Clinic.find( clinic )).doctors.uniq )
end
helper_method :findDoctorViaClinic
def findScheduleViaDoctor(d)
s = Schedule.includes(:doctors_workplace).where(doctors_workplace_id: (DoctorsWorkplace.includes(:doctor).where(doctor_id: d)) ).where(taken: 0)
return s
end
helper_method :findScheduleViaDoctor
def edit
end
def create
#appointment = #wizard.object
if #wizard.save
s = ( Schedule.find( #appointment.schedule.id ) )
s.taken = true
s.save
redirect_to #appointment, notice: "Appointment saved!"
else
render :new
end
end
def update
# if #wizard.save
# redirect_to #appointment, notice: 'Appointment was successfully updated.'
# else
# render action: 'edit'
# end
#appointment = Appointment.find(params[:id])
#old_appointment = #appointment.dup
respond_to do |format|
if #appointment.update_attributes(params[:appointment])
DefaultMailer.move_appointment(#appointment, #old_appointment).deliver
format.html { redirect_to appointments_success_path, notice: 'Pomyslnie zmieniono termin.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: #appointment.errors, status: :unprocessable_entity }
end
end
end
def destroy
#appointment.destroy
redirect_to appointments_url
end
private
def load_appointment
#appointment = Appointment.find(params[:id])
end
def load_wizard
#wizard = ModelWizard.new(#appointment || Appointment, session, params)
if self.action_name.in? %w[new edit]
#wizard.start
elsif self.action_name.in? %w[create update]
#wizard.process
end
end
end
Logs:
Started POST "/appointments/create51" for 127.0.0.1 at 2014-06-22 08:22:53 +0200
Processing by AppointmentsController#create51 as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"kMxnErrH13opSkUPbg9hRM0Sy5JVwDCAbGRDNP5BSfc=", "appointment"=>{"data_godzina_wizyty(1i)"=>"2015", "data_godzina_wizyty(2i)"=>"1", "data_godzina_wizyty(3i)"=>"17", "data_godzina_wizyty(4i)"=>"16", "data_godzina_wizyty(5i)"=>"15", "doctor_id"=>"1", "patient_id"=>"1"}, "commit"=>"Utworz wizyte"}
[1m[35m (0.0ms)[0m begin transaction
[1m[36mSQL (2.0ms)[0m [1mINSERT INTO "appointments" ("clinic_id", "created_at", "data_godzina_wizyty", "data_wizyty", "doctor_id", "godzina_wizyty", "notatka", "objawy_choroby", "patient_id", "potwierdzona", "refferal_id", "schedule_id", "updated_at", "wymaga_Potwierdzenia") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)[0m [["clinic_id", nil], ["created_at", Sun, 22 Jun 2014 06:22:53 UTC +00:00], ["data_godzina_wizyty", nil], ["data_wizyty", nil], ["doctor_id", nil], ["godzina_wizyty", nil], ["notatka", nil], ["objawy_choroby", nil], ["patient_id", nil], ["potwierdzona", nil], ["refferal_id", nil], ["schedule_id", nil], ["updated_at", Sun, 22 Jun 2014 06:22:53 UTC +00:00], ["wymaga_Potwierdzenia", nil]]
[1m[35m (13.0ms)[0m commit transaction
Redirected to http://localhost:3000/appointments/30
Completed 302 Found in 23.0ms (ActiveRecord: 15.0ms)
Started GET "/appointments/new51" for 127.0.0.1 at 2014-06-22 08:22:42 +0200
Processing by AppointmentsController#new51 as HTML
[1m[35mDoctor Load (1.0ms)[0m SELECT "doctors".* FROM "doctors" WHERE "doctors"."id" = ? LIMIT 1 [["id", 1]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "doctors".* FROM "doctors" WHERE "doctors"."id" = ? LIMIT 1[0m [["id", 1]]
[1m[35mCACHE (0.0ms)[0m SELECT "doctors".* FROM "doctors" WHERE "doctors"."id" = ? LIMIT 1 [["id", 1]]
[1m[36mPatient Load (0.0ms)[0m [1mSELECT "patients".* FROM "patients" WHERE "patients"."id" = ? LIMIT 1[0m [["id", 1]]
[1m[35mCACHE (0.0ms)[0m SELECT "patients".* FROM "patients" WHERE "patients"."id" = ? LIMIT 1 [["id", 1]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "patients".* FROM "patients" WHERE "patients"."id" = ? LIMIT 1[0m [["id", 1]]
[1m[35mCACHE (0.0ms)[0m SELECT "doctors".* FROM "doctors" WHERE "doctors"."id" = ? LIMIT 1 [["id", 1]]
[1m[36mCACHE (0.0ms)[0m [1mSELECT "patients".* FROM "patients" WHERE "patients"."id" = ? LIMIT 1[0m [["id", 1]]
Rendered appointments/_form51.html.erb (13.0ms)
Rendered appointments/new51.html.erb within layouts/application (22.0ms)
Rendered welcome/_form.html.erb (1.0ms)
Completed 200 OK in 103.0ms (Views: 100.9ms | ActiveRecord: 1.0ms)
Started GET "/appointments/30" for 127.0.0.1 at 2014-06-22 08:22:53 +0200
Processing by AppointmentsController#show as HTML
Parameters: {"id"=>"30"}
[1m[36mAppointment Load (0.0ms)[0m [1mSELECT "appointments".* FROM "appointments" WHERE "appointments"."id" = ? LIMIT 1[0m [["id", "30"]]
Rendered appointments/show.html.erb within layouts/application (2.0ms)
Rendered welcome/_form.html.erb (1.0ms)
Completed 200 OK in 80.0ms (Views: 77.0ms | ActiveRecord: 0.0ms)
Routes
Wow your routes are really WET
You really need to read up on resourceful routing - every route you have in your routes file really needs to be associated to a particular controller (apart from root to and other wildcards)
Whoever wrote your routes file has laden it with massive numbers of specific actions. Frankly, it's a mess and I would highly recommend you go through & remove any custom actions you've got in there.
Resourceful routing is described in the Rails docs as thus:
Bottom line is you shouldn't be creating routes for specific records; you need to create a system to handle the different processes your application will have
--
Form
If you're not seeing any object created in your db, there could be a number of problems. The biggest, though, is your use of an #instance variable in your partial.
To the best of my knowledge, partials don't carry #instance variables through to their render process. You have to pass local variables:
#new.html.erb
<%= render "form51", locals: { appointment: #appointment } %>
#_form51.html.erb
<%= form_for appointment do |f| %>
...
<% end %>
--
Being honest, there's so much to fix with this, it will be best if you ask for help in the comments here - so I can pinpoint exactly what needs to be fixed
You problem comes from the url you use on your form.
You should try like this on your _form51.html.erb:
form_for #appointment, :url => url_for(:action => "create51") do |f|
If you do rake routes | grep 'create51' you'll have the rails path. Then you can also do like this:
form_for #appointment, :url => create51_path do |f|
(here I suppose the command gave you create51 as path).

can't register my variable in the database

i get an error when i clic on my button sumbit
the error say undefined method `strftime' for nil:NilClass
when i debugge my application i see something strange
tarted POST "/users/2/calendars" for 127.0.0.1 at 2013-05-24 19:44:25 +0200
Processing by CalendarsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"8l0+IDaC+tAHdQi+yvpnWEJRHrR8hNwBA3zgaSBoovQ=", "calendar"=>{"event"=>"aze", "published_on"=>"2013-05-07", "description"=>"rrrrrrr"}, "commit"=>"Create Calendar", "user_id"=>"2"}
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1
(0.1ms) BEGIN
SQL (0.2ms) INSERT INTO `calendars` (`created_at`, `description`, `event`, `published_on`, `updated_at`, `user_id`) VALUES ('2013-05-24 17:44:26', NULL, NULL, NULL, '2013-05-24 17:44:26', 2)
(79.8ms) COMMIT
Redirected to http://127.0.0.1:3000/users/2/calendars/39
Completed 302 Found in 93ms (ActiveRecord: 80.3ms)
cache: [GET /users/2/calendars/39] miss
why he doesn't take my variable event, published_on description i dont understand .
i have missing something ?
calendar.model
class Calendar < ActiveRecord::Base
attr_accessible :event, :published_on, :description, :user_id
belongs_to :user#, :foreign_key => :user_id
end
user.model
has_many :calendar#, :foreign_key => :user_id
accepts_nested_attributes_for :calendar
#attr_accessible :calendar_id
end
calendar.controler
def index
#user = current_user
##content_calendars = #user.Calendar
#content_calendars = #user.Calendar.all
#content_calendars_by_dates = #content_calendars.group_by(&:published_on)
#date = params[:date] ? Date.parse(params[:date]) : Date.today
end
def show
#user = current_user
# #calendar = #user.find_all_calendar_by()
# #tasks = #project.tasks.find_all_by_complete(false)
#calendar = #user.calendar.find(params[:id])
end
def new
#user = current_user
#calendar = #user.calendar.new
##calendar = #user.calendar.build
end
# GET /calendars/1/edit
def edit
#user = current_user
#calendar = #user.Calendar.find(params[:id])
end
# POST /calendars
# POST /calendars.json
def create
#user = current_user
#calendar = #user.calendar.new(params[:current_user])
##calendar = #user.Calendar.new(params[:calendar])
if #calendar.save
#redirect_to calendar_path(#user)
redirect_to [#user,#calendar]
#, notice: "L evenement a ete cree"
else
render :new
end
end
# PUT /calendars/1
# PUT /calendars/1.json
def update
#user = current_user
#calendar = #user.Calendar.find(params[:id])
if #calendar.update_attributes(params[:id])
redirect_to [#user, #calendar]#, notice: "L article a ete mis a jour"
else
render :edit
end
end
# DELETE /calendars/1
# DELETE /calendars/1.json
def destroy
#user = current_user
#calendar.destroy
respond_to do |format|
format.html { redirect_to calendars_url }
format.json { head :no_content }
end
end
private
def find_user
#user = current_user
##user = User.first
##user ||= User.find(session[:user_id]) if session[:user_id]
#findession[:user_id])
end
thanks again for your help guy
I don't really understand where you are facing error, so please paste the code of Controller. Based on your explanation, I am feeling that you should get calender's parameter like below. I think your controller should create object like this from calender parameters:
#calender = Calender.new(params[:calender])
#calender.user_id = params[:user_id]
Hope that helps!!!

Resources