ransack search is missing a param - ruby-on-rails

I am trying to create search form using ransack on rails. I have run into a small problem.
I get an error
param is missing or the value is empty: information
When I submit the search.
Information_controller.rb
class InformationController < ApplicationController
before_action :set_information, only: [:show, :edit, :update, :destroy]
respond_to :html
# Add the breadcrumbs
require 'uri'
# User must authenticate to use all actions in the users controller
before_filter :authenticate_user!, except: [ :home, :show, :splash]
def index
#search = Information.search(params[:q])
#information = params[:distinct].to_i.zero? ?
#search.result :
#search.result(distinct: true)
#information = #information.page(params[:page]).per(10)
respond_with #information
end
def admin
#search = Information.search(params[:q])
#information = #search.result
#search.build_condition
end
#def search
##q = Information.ransack(params[:q])
##information = #q.result(distinct: true)
#end
# GET /information/1
# GET /information/1.json
def show
session[:return_to] = request.fullpath
end
# GET /information/new
def new
#information = Information.new
end
# GET /information/1/edit
def edit
end
# POST /information
# POST /information.json
def create
#information = Information.new(information_params)
respond_to do |format|
if #information.save
format.html { redirect_to #information, notice: 'Entry was successfully created.' }
format.json { render :show, status: :created, location: #information }
else
format.html { render :new }
format.json { render json: #information.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /information/1
# PATCH/PUT /information/1.json
def update
respond_to do |format|
if #information.update(information_params)
format.html { redirect_to #information, notice: 'Entry was successfully updated.' }
format.json { render :show, status: :ok, location: #information }
else
format.html { render :edit }
format.json { render json: #information.errors, status: :unprocessable_entity }
end
end
end
# DELETE /information/1
# DELETE /information/1.json
def destroy
#information.destroy
respond_to do |format|
format.html { redirect_to information_index_url, notice: 'Entry was successfully removed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_information
#information = Information.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def information_params
params.require(:information).permit(:name, :description, :show, :date, :heading, :subheading, :image, :places, :data_type, :reference)
end
end
Search form
<%= search_form_for(
#search,
:url => admin_index_path,
html: { method: :post }
) do |f| %>
<%= f.condition_fields do |c| %>
<%= render "condition_fields", f: c%>
<% end %>
<p><%= link_to_add_fields "Add Conditions", f, :condition %>
<div class="actions"><%= f.submit "Search" %></div>
<% end %>
routes
Rails.application.routes.draw do
root :to => 'information#splash'
devise_for :users, :skip => [:sessions], :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
as :user do
get 'signin' => 'devise/sessions#new', :as => :new_user_session
post 'signin' => 'devise/sessions#create', :as => :user_session
delete 'signout' => 'devise/sessions#destroy', :as => :destroy_user_session
end
##########################################
# ADMIN #
##########################################
#admin panel
get '/admin' => 'information#admin'
#get '/admin/new' => 'information'
resources :information, path: '/admin'
get '/home/:id', to: 'information#show'
get 'home' => 'information#index', :as => :home
concern :paginatable do
get '(page/:page)', :action => :index, :on => :collection, :as => ''
end
concern :paginatable do
get '(page/:page)', :action => :information, :on => :collection, :as => ''
end
#get '/new' => 'information#new'
#get '/public' => 'information#'
##########################################################
resources :information
resources :admin
end
Thank you. If you need more details please ask :^)

Related

Rails: Post JSON to API Using Rails and HTTParty

I'm fairly new to API in Rails, and so I will need some assistance for the issue that I am facing.
All I want is to create a record on the database of the API through a POST request from my application.
That is to create a record on both databases (my database and the on the database of the API through a POST request from my application) whenever I create a book.
So this is what I've done so far:
For the app that will consume the API I am using the HTTParty gem.
I have tried to implement in my create action of the Books Controller using the code below:
#result = HTTParty.post(' https://www.pingme.com/wp-json/wplms/v1/user/register',
:body => { :name => '#{name}',
:author => '#{author}',
:description => '#{description}',
:category_id => '#{category_id}',
:sub_category_id => '#{sub_category_id}'}.to_json,
:headers => { 'Content-Type' => 'application/json', 'Authorization' => '77d22458349303990334xxxxxxxxxx' })
Here is my Books Controller for creating books
require 'httparty'
class BooksController < ApplicationController
include HTTParty
before_action :set_book, only: [:show, :edit, :update, :destroy]
before_action :authenticate_admin!, except: %i[show index]
skip_before_action :verify_authenticity_token
# GET /books
# GET /books.json
def index
#books = Book.search(params[:keywords]).paginate(:page => params[:page], :per_page => 9).order('created_at DESC')
end
# GET /books/1
# GET /books/1.json
def show
end
# GET /books/new
def new
#book = Book.new
end
# GET /books/1/edit
def edit
end
# POST /books
# POST /books.json
def create
#book = Book.new(book_params)
respond_to do |format|
if #book.save
format.html { redirect_to #book, notice: 'Book was successfully created.' }
format.json { render :show, status: :created, location: #book }
else
format.html { render :new }
format.json { render json: #book.errors, status: :unprocessable_entity }
end
end
#result = HTTParty.post(' https://www.pingme.com/wp-json/wplms/v1/user/register',
:body => { :name => '#{name}',
:author => '#{author}',
:description => '#{description}',
:category_id => '#{category_id}',
:sub_category_id => '#{sub_category_id}'}.to_json,
:headers => { 'Content-Type' => 'application/json', 'Authorization' => '77d22458349303990334xxxxxxxxxx' })
end
# PATCH/PUT /books/1
# PATCH/PUT /books/1.json
def update
respond_to do |format|
if #book.update(book_params)
format.html { redirect_to #book, notice: 'Book was successfully updated.' }
format.json { render :show, status: :ok, location: #book }
else
format.html { render :edit }
format.json { render json: #book.errors, status: :unprocessable_entity }
end
end
end
# DELETE /books/1
# DELETE /books/1.json
def destroy
#book.destroy
respond_to do |format|
format.html { redirect_to books_url, notice: 'Book was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_book
#book = Book.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def book_params
params.require(:book).permit(:name, :author, :description, :category_id, :sub_category_id)
end
end
But it still doesn't create these books on the database of the API through the post request when I create books.
Please any form of assistance will be highly appreciated.
Thank you.
Check you logs when you do the request, but I suspect you need to change your body to:
{
:book => {
:name => '#{name}',
:author => '#{author}',
:description => '#{description}',
:category_id => '#{category_id}',
:sub_category_id => '#{sub_category_id}'
}
}.to_json
Note that book key at the top is the difference.
Following contributions from #paulo-fidalgo and #tejasbubane, I found a working solution to the issue.
Here is the corrected HTTParty Post Request
#results = HTTParty.post(' https://www.pingme.com/wp-json/wplms/v1/user/register',
:body => {
:name => "#{#book.name}",
:author => "#{#book.author}",
:description => "#{#book.description}",
:category_id => "#{#book.category_id}",
:sub_category_id => "#{#book.sub_category_id}"}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Authorization' => '77d22458349303990334xxxxxxxxxx'
}
)

Ruby on Rails/How to Scaffold form link to specific action?

My scaffold model doesn't work well with create action.
I found out that if I press submit button, it is linked to TalksController#index but it should be linked to TalksController#create
I don't know how I can fix it to link to create action. There aren't any codes related to it in _form.html.erb and new.html.erb
Create worked well 2 days ago.
[edit]I post my codes.
I added some codes in addition to the codes scaffold made itself
talks_controller.rb
class TalksController < ApplicationController
before_action :set_talk, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [ :index, :show, :all ]
# GET /talks
# GET /talks.json
def all
#talks = Talk.all
#talks = Talk.order(created_at: :desc)
end
def index
#talks = Talk.all
#talks = Talk.order(created_at: :desc)
#whichboard = params[:whichboard]
#seq = params[:saveit]
#title = params[:savetitle]
end
# GET /talks/1
# GET /talks/1.json
def show
end
# GET /talks/new
def new
#talk = Talk.new
#seq = params[:seq]
#whichboard = params[:whichboard]
end
# GET /talks/1/edit
def edit
authorize_action_for #talk
end
# POST /talks
# POST /talks.json
def create
#talk = Talk.new(talk_params)
#talk.user_id = current_user
#talk.seq = params[:talk][:seq]
#talk.where = params[:talk][:where]
respond_to do |format|
if #talk.save
format.html { redirect_to #talk, notice: 'Talk was successfully created.' }
format.json { render :index, status: :created, location: #talk }
else
format.html { render :new }
format.json { render json: #talk.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /talks/1
# PATCH/PUT /talks/1.json
def update
authorize_action_for #talk
respond_to do |format|
if #talk.update(talk_params)
format.html { redirect_to #talk, notice: 'Talk was successfully updated.' }
format.json { render :show, status: :ok, location: #talk }
else
format.html { render :edit }
format.json { render json: #talk.errors, status: :unprocessable_entity }
end
end
end
# DELETE /talks/1
# DELETE /talks/1.json
def destroy
authorize_action_for #talk
#talk.destroy
respond_to do |format|
format.html { redirect_to talks_url, notice: 'Talk was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_talk
#talk = Talk.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def talk_params
params.require(:talk).permit(:content, :user_id, :seq, :where)
end
end
_form.html.erb
<%= simple_form_for(#talk) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :content %>
<%#= f.association :user %>
<%= f.input :seq, :as => :hidden, :input_html => { :value => #seq } %>
<%= f.input :where, :as => :hidden, :input_html => { :value => #whichboard } %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
new.html.erb
<div class="row">
<div class='col-md-12'>
<p style='text-align:right;'>
created by <%= current_user.name %>, Current Time : <%= Time.now %>, board <%= #whichboard %> seq <%= #seq %>
</p>
</div>
</div>
<%= render 'form' %>
<%= link_to 'Back', talks_path %>
[SECOND EDIT] routes.rb
Rails.application.routes.draw do
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
root 'cpu#index'
post ':controller(/:action(/:id(.:format)))'
get ':controller(/:action(/:id(.:format)))'
resources :talks
end
adjust your routes.rb
Rails.application.routes.draw do
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
root 'cpu#index'
resources :talks
#do you really need these?
post ':controller(/:action(/:id(.:format)))'
get ':controller(/:action(/:id(.:format)))'
end
to put the resources :talks above the default/catchall routes. the routes are processed on first match, so if you need those default/catchalls youcan put them at the bottom. That being said, unless you have a requirement for them most modern rails apps don't require them by default, so you can probably comment out / remove them as another option.
The index and create both refer to the same url or the same route method, the only difference is the method if you use the method as post then, it'll go to create otherwise it goes to index. But, you could implicitly handle this if you pass in the new instance of the object you are trying to create such as #customer = Customer.new then, pass #customer to the form_for method.
With the form_for method, you can specify url of the action you want to be executed or just controller and action like this:
<%= form_for #post, :url => {:controller => "your-controller-name", :action => "your-action-name"} do |f| %>
And in your action ("your-action-name") you can call your parameters like:
post_id = params[:post][:id]
Hope that will help you.

Rails, How i can create grouped_select?

I'm new in rails and i need a help.
I wanna to do a grouped selection on rails but i dont know how i can do it.
i have 3 db tables cars, car_brands and car_models. When i add new car i need to select car model, how i can do it with gtouped selection.
models/car_brand.rb
class CarBrand < ActiveRecord::Base
has_many :cars
has_many :car_models
mount_uploader :logo, CarBrandImgUploader
end
models/car_model.rb
class CarModel < ActiveRecord::Base
has_many :cars
belongs_to :car_brand
end
cars_controller.rb
class CarsController < ApplicationController
before_action :set_car, only: [:show, :edit, :update, :destroy]
before_action :set_model, only: [:index, :new, :edit]
# GET /cars
# GET /cars.json
def index
#cars = Car.all
end
# GET /cars/1
# GET /cars/1.json
def show
end
# GET /cars/new
def new
#car = Car.new
end
# GET /cars/1/edit
def edit
end
# POST /cars
# POST /cars.json
def create
#car = Car.new(car_params)
respond_to do |format|
if #car.save
if params[:ImagesCars]
params[:ImagesCars]['image'].each do |a|
#ImagesCar = #car.ImagesCars.create!(:image => a, :car_id => #car.id)
end
end
format.html { redirect_to #car, notice: 'Car was successfully created.' }
format.json { render :show, status: :created, location: #car }
else
format.html { render :new }
format.json { render json: #car.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /cars/1
# PATCH/PUT /cars/1.json
def update
respond_to do |format|
if #car.update(car_params)
if params[:ImagesCars]
params[:ImagesCars]['image'].each do |a|
#ImagesCar = #car.ImagesCars.create!(:image => a, :car_id => #car.id)
end
end
format.html { redirect_to #car, notice: 'Car was successfully updated.' }
format.json { render :show, status: :ok, location: #car }
else
format.html { render :edit }
format.json { render json: #car.errors, status: :unprocessable_entity }
end
end
end
# DELETE /cars/1
# DELETE /cars/1.json
def destroy
#car.destroy
respond_to do |format|
format.html { redirect_to cars_url, notice: 'Car was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_car
#car = Car.find(params[:id])
end
def set_model
#models = CarModel.all
#brands = CarBrand.all
end
# Never trust parameters from the scary internet, only allow the white list through.
def car_params
params.require(:car).permit(:title_en, :keys_en, :description_en, :text_en, :title_fr, :keys_fr, :description_fr, :text_fr, :title_ru, :keys_ru, :description_ru, :text_ru, :title_es, :keys_es, :description_es, :text_es, :model_id, :brand_id, :price_day, :price_week, :p_info, :images_cars => [:id, :car_id, :image])
end
end
cars/new.html.haml
= simple_form_for(#car, html: { role: 'form', multipart: true }) do |f|
= f.input :price_day, as: :integer, input_html: {class: 'form-control', placeholder: 'Price Day ej: 150'}
= f.cktext_area :text_en, as: :text, input_html: { class: 'form-control' }, :label => 'EN Website Content Text EN'
=f.input :model_id, collection: #models, as: :grouped_select, group_method: :brand_id
= f.submit 'Save'
i get this error:
undefined method `map' for nil:NilClass
Please help or explain how i can do the grouped selection.
Thx

Rails - using link_to on application.html.erb for nested resource not getting id

I have a sidebar on application.html.erb, and the links should go to /brands/[brand_id]/coupons
I used brand_coupons_path(#brand) but I get an error saying 'No route matches {:action=>"index", :brand_id=>nil, :controller=>"coupons"} missing required keys: [:brand_id]'
resources :brands do
resources :coupons, :sales
end
class Brand < ActiveRecord::Base
has_many :coupons
has_many :sales
accepts_nested_attributes_for :coupons
accepts_nested_attributes_for :sales
end
class Coupon < ActiveRecord::Base
belongs_to :brand
end
<div class="sidebar">
<ul class="sidebar-list">
<li><a class="sidebar-header">Most Popular Brands</a></li>
<% #brands.each do |brand| %>
<% if current_page?(:controller => 'coupons') %>
<li><%= link_to brand.name, brand_coupons_path(#brand), :class => "sidebar-link" %></li>
<% else %>
<li><%= link_to brand.name, brand_sales_path(#brand), :class => "sidebar-link" %></li>
<% end %>
<% end %>
</ul>
</div>
class CouponsController < ApplicationController
before_action :set_coupon, only: [:show, :edit, :update, :destroy]
# before_filter :load_brand
def new
#coupon = Coupon.new
end
def index
#coupons = Coupon.where(brand_id: params[:brand_id])
end
def show
end
def create
#coupon = Coupon.new(coupon_params)
respond_to do |format|
if #coupon.save
format.html { redirect_to '/', notice: 'Coupon was successfully created.' }
format.json { render :show, status: :created, location: #coupon }
else
format.html { render :new }
format.json { render json: #coupon.errors, status: :unprocessable_entity }
end
end
end
class BrandsController < ApplicationController
before_action :set_brand, only: [:show, :edit, :update, :destroy]
# GET /brands
# GET /brands.json
def index
#brands = Brand.all
end
# GET /brands/1
# GET /brands/1.json
def show
end
# GET /brands/new
def new
#brand = Brand.new
end
# GET /brands/1/edit
def edit
end
# POST /brands
# POST /brands.json
def create
#brand = Brand.new(brand_params)
respond_to do |format|
if #brand.save
format.html { redirect_to #brand, notice: 'Brand was successfully created.' }
format.json { render :show, status: :created, location: #brand }
else
format.html { render :new }
format.json { render json: #brand.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /brands/1
# PATCH/PUT /brands/1.json
def update
respond_to do |format|
if #brand.update(brand_params)
format.html { redirect_to #brand, notice: 'Brand was successfully updated.' }
format.json { render :show, status: :ok, location: #brand }
else
format.html { render :edit }
format.json { render json: #brand.errors, status: :unprocessable_entity }
end
end
end
# DELETE /brands/1
# DELETE /brands/1.json
def destroy
#brand.destroy
respond_to do |format|
format.html { redirect_to brands_url, notice: 'Brand was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_brand
#brand = Brand.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def brand_params
params.require(:brand).permit(:name, :logo)
end
end
You're passing an undefined #brand variable into your routes helpers, rather than the block variable brand. Change:
<%= link_to brand.name, brand_coupons_path(#brand), :class => "sidebar-link" %>
<%= link_to brand.name, brand_sales_path(#brand), :class => "sidebar-link" %>
to
<%= link_to brand.name, brand_coupons_path(brand), :class => "sidebar-link" %>
<%= link_to brand.name, brand_sales_path(brand), :class => "sidebar-link" %>
What does #brand contains? I think you should put an object to #brand variable.
Like this. #brand = Brand.find(params[:id])
Can we see the controller of your index?

Ruby error with form

how to make route from appointment/new51 action to create51 action ? because it automatically redirect me to create and I don't want this. I am new in Ruby and I have lots of problems with my school project but it is almost finished:)
Routes.rb:
ZOZ::Application.routes.draw do
resources :refferals do
collection do
get 'new51'
end
member do
get 'show'
end
end
#17 potwierdzanie rejestracji
resources :appointments do
collection do
get 'search'
get 'search_result'
get 'to_confirm'
get 'new51'
end
member do
put :confirm
put :create51
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'
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
Appointments_controller:
class AppointmentsController < ApplicationController
before_filter :load_appointment, only: [:show, :update, :edit, :destroy]
before_filter :load_wizard, only: [:new, :edit, :create, :update]
def search
end
def new51
#doctors_workplace = DoctorsWorkplace.scoped
#doctors_workplace = #doctors_workplace.where(doctor_id: Doctor.find(session[:current_doctor_id2]).id)
#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[:appointment])
respond_to do |format|
if #appointment.save
format.html { redirect_to #appointment, notice: 'Appointment was successfully created.' }
format.json { render json: #appointment, status: :created, location: #appointment }
else
format.html do
#schedules = Schedule.scoped
#schedules = #schedules.where(doctor_id: Doctor.find(session[:current_doctor_id2]).id)
render action: "new51"
end
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
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
_form51:
<%= 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 %>
wymaga_Potwierdzenia != wymaga_potwierdzenia
Correct to the right method/column name.

Resources