Class: Auth::Shopping::BarCodesController
- Inherits:
-
ShoppingController
- Object
- ShoppingController
- Auth::Shopping::BarCodesController
- Includes:
- Concerns::DeviseConcern, Concerns::TokenConcern
- Defined in:
- app/controllers/auth/shopping/bar_codes_controller.rb
Constant Summary collapse
- CONDITIONS_FOR_TOKEN_AUTH =
NEW CAN BE ACCESSED BY ANY USER ,NOT NECESSARILY AN AUTHENTICATED USER OR ANYTHING.
[:index,:show]
- TCONDITIONS =
{:only => CONDITIONS_FOR_TOKEN_AUTH}
Instance Method Summary collapse
- #get_model_params ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #permitted_params ⇒ Object
-
#show ⇒ Object
then you pass in a parameter like that.
Instance Method Details
#get_model_params ⇒ Object
104 105 106 |
# File 'app/controllers/auth/shopping/bar_codes_controller.rb', line 104 def get_model_params permitted_params.fetch(:bar_code,{}) end |
#index ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/auth/shopping/bar_codes_controller.rb', line 17 def index page_number = params[:page_number].nil? ? 1 : params[:page_number] page_size = params[:page_size].nil? ? 10 : params[:page_size] ## max page size. page_size = 50 if page_size > 50 skips = page_size * (page_num - 1) @bar_codes = Auth::Shopping::BarCode.all.skip(skips).limit(page_size) respond_to do |format| end end |
#new ⇒ Object
13 14 15 |
# File 'app/controllers/auth/shopping/bar_codes_controller.rb', line 13 def new end |
#permitted_params ⇒ Object
100 101 102 |
# File 'app/controllers/auth/shopping/bar_codes_controller.rb', line 100 def permitted_params params.permit({bar_code: [:bar_code_tag,:force_show,:go_to_next_step]}, :id, :page_number, :page_size) end |
#show ⇒ Object
then you pass in a parameter like that. if force_show is true, then it will
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/auth/shopping/bar_codes_controller.rb', line 37 def show begin @bar_code = Auth::Shopping::BarCode.find(params[:id]) @bar_code.assign_attributes(get_model_params) rescue Mongoid::Errors::DocumentNotFound @bar_code = Auth::Shopping::BarCode.new @bar_code.errors.add(:_id,"not found") end @bar_code.set_assigned_object if (@bar_code.errors..empty?) respond_to do |format| format.js do ## render a partial which will deal with all these eventualities. render :partial => "show" end format.html do if get_model_params[:force_show] render 'auth/shopping/bar_codes/show' else ## now let me first make a show view. if @bar_code.errors.empty? unless @bar_code.assigned_to_object.primary_link.blank? redirect_to @bar_code.assigned_to_object.primary_link else @bar_code.errors.add(:_id,"no primary link defined on the assigned object") render 'auth/shopping/bar_codes/show' end else render 'auth/shopping/bar_codes/show' end end end format.json do if get_model_params[:force_show] render :json => {bar_code: @bar_code}, status: 200 else if @bar_code.errors.empty? if @bar_code.assigned_to_object unless @bar_code.assigned_to_object.primary_link.blank? ## it should have its primary link. render :json => {redirect_to: @bar_code.assigned_to_object.primary_link} else @bar_code.errors.add(:_id,"no primary link defined on the assigned object") render :json => {bar_code: @bar_code, errors: @bar_code.errors}, status: 422 end else render :json => {bar_code: @bar_code}, status: 200 end else render :json => {bar_code: @bar_code, errors: @bar_code.errors}, status: 422 end end end end end |