I'm new to ruby on rails. I tried to redirect to outlet_controller#map, but the below code redirect me to #show. what i am doing wrong. help me to sort out.
my route is
namespace :api do
get 'outlet/map' => 'outlets#map'
end
my controller is
class Api::OutletsController < ApplicationController
http_basic_authenticate_with :name => "admin", :password => "password"
skip_before_filter :authenticate_user!
before_filter :fetch_outlets, :except => [:index, :create]
def fetch_outlets
@outlet = Outlet.find_by_id(params[:id])
end
def index
respond_to do |format|
@outlets = Outlet.select(:name, :description, :latitude, :longitude, :contact, :image_url, :emailid).all
#@outlets = Outlet.all
format.json { render json: @outlets}
end
end
def auto_complete
params.permit!
query = params[:query]
@outlet = Outlet.select(:name).where("name like ?","#{query}%")
if @outlet.present?
respond_to do |format|
format.json { render json: @outlet }
end
elsif
render :json=> {:status=>'error', :message=>'Data not found'}
end
end
def search
params.permit!
query = params[:query]
puts YAML::dump(query)
@outlet = Outlet.select(:name, :description, :latitude, :longitude, :contact, :image_url, :emailid).where("name like ?","%#{query}%")
if @outlet.present?
respond_to do |format|
format.json { render json: @outlet }
end
elsif
render :json=> {:status=>'error', :message=>'Data not found'}
end
end
def show
respond_to do |format|
format.json { render json: @outlet }
end
end
def create
@outlet = Outlet.new(params[:outlets])
respond_to do |format|
if @outlet
format.json { render json: @outlet, status: :created }
else
format.json { render json: @outlet.errors, status: :unprocessable_entity }
end
end
end
def update
if @outlet.update_attributes(outlet_params)
render :json=> {:status=>'success', :message=>'Successfully Updated'}
else
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
def map
super
end
def destroy
if @outlet.destroy
render :json=> {:status=>'success', :message=>'Successfully Removed'}
else
format.json { render json: @outlet.errors, status: :unprocessable_entity }
end
end
private
def outlet_params
params.require(:outlets).permit(:name, :brand_id, :latitude, :langitude, :location, :description, :image_url, :contact, :emailid)
end
end
my development log for
/api/outlets/map
is
Started GET "/api/outlets/map" for 127.0.0.1 at 2015-06-01 17:18:59 +0530
Processing by Api::OutletsController#show as JSON
Parameters: {"id"=>"map"}
[1m[35mOutlet Load (0.2ms)[0m SELECT `outlets`.* FROM `outlets` WHERE `outlets`.`id` = 0 LIMIT 1
Completed 200 OK in 15ms (Views: 0.3ms | ActiveRecord: 0.2ms)
why i'm redirect to outlets_controller#show? could anyone help to sort out this problem...
Aucun commentaire:
Enregistrer un commentaire