ruby on rails - How can I use a bingInt (as string) as a parameter? -
so i'm creating system visitor can ask client music composition. user starts fill form details , such, , when submits it, it's not yet sent client. however, can estimation of price, , modify demand if wants to. after that, still can submit 1 last time, , time, estimation sent.
i don't want use default id parameter because way simple 'parse' other estimations if url looks ends /3
or /4
. you'd have try few urls , if it's lucky day, you'd "hack" estimation isn't yours. i'm planning use cron job delete these estimations after while, don't want take risk.
to avoid that, decided use visitor's session_id parameter, on removed every alphabetic characters, still saved string in mysql 5.7 database activerecord ok that. changed routes accordingly, , result supposed
localhost:3000/devis/4724565224204064191099 # devis means 'quotation' in french
however, when try route, following error:
activerecord::recordnotfound (couldn't find devi out of range value 'id')
here relevant part of controller:
devis_controller.rb
# ... def create @devi = devi.new(devi_params) respond_to |format| @devi.status = 'created' @devi.session_id = session.id.gsub(/[^\d]/, '').to_s # how store parameter # latest record returns '4724565224204064191099' if @devi.save format.html { redirect_to @devi, notice: 'devi created.' } format.json { render :show, status: :created, location: @devi } else format.html { render :new } format.json { render json: @devi.errors, status: :unprocessable_entity } end end end # ... private def set_devi @devi = devi.find(params[:session_id].to_s) # tried '.to_s', didn't work end
and here routes:
# 'index' , 'destroy' don't exist resources :devis, only: %i(create update) '/devis/nouveau', to: 'devis#new', as: :devis_new '/devis/:session_id', to: 'devis#show', as: :devis_show '/devis/editer/:session_id', to: 'devis#edit', as: :devis_edit
my question following: there way present :session_id
string controller's params? or have better option?
thank you
i think session_id int @ database, , should change.
change type of session_id string , activerecord map session_id string on
Comments
Post a Comment