usda linking

This commit is contained in:
Dan Elbert 2016-01-29 18:45:20 -06:00
parent 2dca779294
commit ff231ceee0
2 changed files with 10 additions and 5 deletions

View File

@ -1,6 +1,6 @@
class IngredientsController < ApplicationController class IngredientsController < ApplicationController
before_action :set_ingredient, only: [:edit, :update, :destroy, :select_ndbn] before_action :set_ingredient, only: [:edit, :update, :destroy]
before_filter :ensure_valid_user, only: [:new, :edit, :create, :update, :destroy] before_filter :ensure_valid_user, only: [:new, :edit, :create, :update, :destroy]
@ -64,7 +64,14 @@ class IngredientsController < ApplicationController
end end
def select_ndbn def select_ndbn
if params[:id].present?
@ingredient = Ingredient.find(params[:id])
else
@ingredient = Ingredient.new
end
@ingredient.assign_attributes(ingredient_params) @ingredient.assign_attributes(ingredient_params)
if @ingredient.ndbn.present? if @ingredient.ndbn.present?
@ingredient.set_usda_food(UsdaFood.find_by_ndbn(@ingredient.ndbn)) @ingredient.set_usda_food(UsdaFood.find_by_ndbn(@ingredient.ndbn))
end end

View File

@ -16,12 +16,10 @@ Rails.application.routes.draw do
get :convert get :convert
end end
end end
member do
match :select_ndbn, via: [:post, :patch, :put]
end
end end
match '/ingredients(/:id)/select_ndbn' => 'ingredients#select_ndbn', via: [:post, :patch, :put]
resource :user, only: [:new, :create, :edit, :update] resource :user, only: [:new, :create, :edit, :update]
get '/login' => 'users#login', as: :login get '/login' => 'users#login', as: :login