Code Monkey home page Code Monkey logo

bar_roulette_app's People

Contributors

jon-eng avatar

Watchers

 avatar

bar_roulette_app's Issues

Rails Backbone Integration

CONTEXT

@harimohanraj89 @DrRobotmck @WilliamfShaw @bigtone1284

WHAT USER STORY YOU ARE WORKING ON:

I am working on the user story "As a user, I want to input starting location, distance, bar price and find a random bar with those parameters"

I am working on the search-parameter branch.

WHAT YOU ARE TRYING TO DO:

I am trying to make a call to my api with my search parameters using backbone and rails.

DETAILED DESCRIPTION OF THE BUG/ERROR:

I am passing the search parameters from my front end forms to my search route in rails but I am getting a server error.

GET http://localhost:3000/venues/explore?near=new%20york&radius=15000&price=2 500 (Internal Server Error)

Rails.application.routes.draw do
root 'application#index'
get 'venues/explore' => 'bars#search'

class BarsController < ApplicationController
def search
bar_results = Bar.find_bar(params[:near][:distance][:bar_price])
render json: bar_results
end
end

WHAT I'VE TRIED

I doublechecked that my server is working correctly by manually entering a URL to hit my server's search route in my URL bar, and confirmed that my server is ok. The URL I tested with is localhost:3000/search?search=potatoes.

I also manually called App.searchResultsCollection.search('potatoes') in my console to test my collection alone. This also worked, as App.searchResultsCollection.models gave me an array of search results.

I inserted a debugger in my searchFormView's searchAPI function to attempt to take a look at whether the search term was being grabbed correctly, but my debugger was never being triggered.

QUESTION

If my server and my collection are ok, then I believe the problem may be with my view, but I am unable to find it. Why is my click event listener not being attached to the search button correctly?

❤️ A meticulous and troubled student

Rails Backbone Integration

CONTEXT

@harimohanraj89 @DrRobotmck @WilliamfShaw @bigtone1284

WHAT USER STORY YOU ARE WORKING ON:

I am working on the user story "As a user, I want to input starting location, distance, bar price and find a random bar with those parameters"

I am working on the search-parameter branch.

WHAT YOU ARE TRYING TO DO:

I am trying to make a call to my api with my search parameters using backbone and rails.

DETAILED DESCRIPTION OF THE BUG/ERROR:

I am passing the search parameters from my front end forms to my search route in rails but I am getting a server error.

GET http://localhost:3000/venues/explore?near=new%20york&radius=15000&price=2 500 (Internal Server Error)

The files involved in my search form are my Bars Controller, Bars Model, routes and my Bars Collection Below is the code for each.

Rails.application.routes.draw do
  root 'application#index'
get 'venues/explore' => 'bars#search'
class BarsController < ApplicationController
  def search
    bar_results = Bar.find_bar(params[:near][:distance][:bar_price])
    render json: bar_results
  end
end
App.Collections.Bars = Backbone.Collection.extend({

  model: App.Models.Bar,

  searchUrl: function (near, distance, bar_price){
  //api.foursquare.com/v2/venues/explore?ll=40.7,-74&client_id=BNAPSUX5Q2VGUM2JOAQGHXHGCK5WGGHWQPF2VWKZJG5XLKUL&client_secret=F4OSS11HXEOPZP41WPYYXDSV2NHR2BYZGZWNX44OJ3PEBLZ0&v=20150401&section=drinks&limit=5&radius=15000&price=2

  // var near = $('#near').val();
  // var distance = $('#distance').val();
  // var bar_price = $('#bar_price').val();

  return '/venues/explore?near=' + encodeURI(near) + '&radius=' + encodeURI(distance) + '&price=' + encodeURI(bar_price) 
  },

  search: function (near, distance, bar_price){
    $.getJSON(this.searchUrl(near, distance, bar_price))
    .done(this.reset.bind(this))
  }

});
class Bar

  BASE_URL = "https://api.foursquare.com/v2/venues/explore"

  CLIENT_ID = "BNAPSUX5Q2VGUM2JOAQGHXHGCK5WGGHWQPF2VWKZJG5XLKUL"

  CLIENT_SECRET = "F4OSS11HXEOPZP41WPYYXDSV2NHR2BYZGZWNX44OJ3PEBLZ0"

  V = "20150401"


  def self.find_bar(near, distance, bar_price)
    bar_data = HTTParty.get(BASE_URL, :query =>{:near => near, :client_id => CLIENT_ID, :client_secret => CLIENT_SECRET, :v => V, :section => "drinks", :limit => "200", :radius => distance, :price => bar_price})

    random_bar = bar_data["response"]["groups"][0]["items"].sample

    random_bar
  end


end

WHAT I'VE TRIED

I've tried changing my controllers and routes and backbone forms but to no avail.

QUESTION

There are so many moving parts in backbone and rails I'm not too sure how everything is connecting. I know the problem is somewhere either in my endpoint or my model, but I can't seem to pinpoint the problem

❤️
A meticulous and troubled student

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.