add new api
This commit is contained in:
3
app/assets/javascripts/api/products.coffee
Normal file
3
app/assets/javascripts/api/products.coffee
Normal file
@@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
3
app/assets/javascripts/products.coffee
Normal file
3
app/assets/javascripts/products.coffee
Normal file
@@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
3
app/assets/stylesheets/api/products.scss
Normal file
3
app/assets/stylesheets/api/products.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the api/products controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
3
app/assets/stylesheets/products.scss
Normal file
3
app/assets/stylesheets/products.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the products controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
19
app/controllers/api/products_controller.rb
Normal file
19
app/controllers/api/products_controller.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class Api::ProductsController < ApplicationController
|
||||
skip_before_filter :verify_authenticity_token
|
||||
|
||||
def index
|
||||
session_token=params[:session_token]
|
||||
check_member= Member.authenticate_session_token(session_token)
|
||||
if !check_member.nil?
|
||||
categories =ProductCategory.all
|
||||
arr_category=Array.new
|
||||
categories.each do |cat|
|
||||
str={:id => cat.id,:name => cat.name}
|
||||
arr_category.push(str)
|
||||
end
|
||||
@out=true,arr_category
|
||||
else
|
||||
@out=false,"Sorry!Unauthorized user!"
|
||||
end
|
||||
end
|
||||
end
|
||||
2
app/helpers/api/products_helper.rb
Normal file
2
app/helpers/api/products_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module Api::ProductsHelper
|
||||
end
|
||||
2
app/helpers/products_helper.rb
Normal file
2
app/helpers/products_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module ProductsHelper
|
||||
end
|
||||
3
app/models/product_category.rb
Normal file
3
app/models/product_category.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class ProductCategory < ApplicationRecord
|
||||
|
||||
end
|
||||
2
app/models/product_type.rb
Normal file
2
app/models/product_type.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class ProductType < ApplicationRecord
|
||||
end
|
||||
7
app/views/api/products/index.json.jbuilder
Normal file
7
app/views/api/products/index.json.jbuilder
Normal file
@@ -0,0 +1,7 @@
|
||||
if @out[0] == true
|
||||
json.set! :status, @out[0]
|
||||
json.set! :data, @out[1]
|
||||
else
|
||||
json.set! :status, @out[0]
|
||||
json.set! :message,@out[1]
|
||||
end
|
||||
Reference in New Issue
Block a user