Class: StockitController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- StockitController
- Defined in:
- app/controllers/stockit_controller.rb
Instance Method Summary collapse
-
#articles_search ⇒ Object
TODO: Fix this!!.
-
#copy ⇒ Object
(2) StockArticle as template.
- #create ⇒ Object
-
#derive ⇒ Object
(3) non-stock Article as template.
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
-
#index_on_stock_article_create ⇒ Object
See publish/subscribe design pattern in /doc.
-
#index_on_stock_article_update ⇒ Object
See publish/subscribe design pattern in /doc.
-
#new ⇒ Object
three possibilites to fill a new_stock_article form (1) start from blank or use params.
- #show ⇒ Object
-
#show_on_stock_article_update ⇒ Object
See publish/subscribe design pattern in /doc.
- #update ⇒ Object
Methods inherited from ApplicationController
Methods included from PathHelper
#finance_group_transactions_path
Instance Method Details
#articles_search ⇒ Object
TODO: Fix this!!
84 85 86 87 |
# File 'app/controllers/stockit_controller.rb', line 84 def articles_search @articles = Article.not_in_stock.limit(8).where('name LIKE ?', "%#{params[:term]}%") render json: @articles.map(&:name) end |
#copy ⇒ Object
(2) StockArticle as template
33 34 35 36 37 |
# File 'app/controllers/stockit_controller.rb', line 33 def copy @stock_article = StockArticle.find(params[:stock_article_id]).dup render layout: false end |
#create ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/controllers/stockit_controller.rb', line 52 def create @stock_article = StockArticle.new({ quantity: 0 }.merge(params[:stock_article])) @stock_article.save! render layout: false rescue ActiveRecord::RecordInvalid render action: 'new', layout: false end |
#derive ⇒ Object
(3) non-stock Article as template
40 41 42 43 44 |
# File 'app/controllers/stockit_controller.rb', line 40 def derive @stock_article = Article.find(params[:old_article_id]).becomes(StockArticle).dup render layout: false end |
#destroy ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'app/controllers/stockit_controller.rb', line 74 def destroy @stock_article = StockArticle.find(params[:id]) @stock_article.mark_as_deleted render layout: false rescue StandardError => e render partial: 'destroy_fail', layout: false, locals: { fail_msg: I18n.t('errors.general_msg', msg: e.) } end |
#edit ⇒ Object
46 47 48 49 50 |
# File 'app/controllers/stockit_controller.rb', line 46 def edit @stock_article = StockArticle.find(params[:id]) render layout: false end |
#index ⇒ Object
2 3 4 5 |
# File 'app/controllers/stockit_controller.rb', line 2 def index @stock_articles = StockArticle.undeleted.includes(:supplier, :article_category) .order('suppliers.name, article_categories.name, articles.name') end |
#index_on_stock_article_create ⇒ Object
See publish/subscribe design pattern in /doc.
7 8 9 10 11 |
# File 'app/controllers/stockit_controller.rb', line 7 def index_on_stock_article_create # See publish/subscribe design pattern in /doc. @stock_article = StockArticle.find(params[:id]) render layout: false end |
#index_on_stock_article_update ⇒ Object
See publish/subscribe design pattern in /doc.
13 14 15 16 17 |
# File 'app/controllers/stockit_controller.rb', line 13 def index_on_stock_article_update # See publish/subscribe design pattern in /doc. @stock_article = StockArticle.find(params[:id]) render layout: false end |
#new ⇒ Object
three possibilites to fill a new_stock_article form (1) start from blank or use params
26 27 28 29 30 |
# File 'app/controllers/stockit_controller.rb', line 26 def new @stock_article = StockArticle.new(params[:stock_article]) render layout: false end |
#show ⇒ Object
19 20 21 22 |
# File 'app/controllers/stockit_controller.rb', line 19 def show @stock_article = StockArticle.find(params[:id]) @stock_changes = @stock_article.stock_changes.order('stock_changes.created_at DESC') end |
#show_on_stock_article_update ⇒ Object
See publish/subscribe design pattern in /doc.
68 69 70 71 72 |
# File 'app/controllers/stockit_controller.rb', line 68 def show_on_stock_article_update # See publish/subscribe design pattern in /doc. @stock_article = StockArticle.find(params[:id]) render layout: false end |
#update ⇒ Object
60 61 62 63 64 65 66 |
# File 'app/controllers/stockit_controller.rb', line 60 def update @stock_article = StockArticle.find(params[:id]) @stock_article.update!(params[:stock_article]) render layout: false rescue ActiveRecord::RecordInvalid render action: 'edit', layout: false end |