Best method for simple GET based Ruby on Rails app - ruby-on-rails

Im trying to understand the best method for creating a basic Rails app that is only interfaced with via GET values in the url. Im attempting to understand how to go about starting to write logic for this as well as generally where i would want to start coding. Would this main interface code be considered a helper? or should i migrate the code to the model?
An example of how i'd like to use this app is something like the following.
http://www.railsapp.com/?order_number=123&print_label=true
With this example url i hope to grab the order_number get some information from it, determine if print_label is true/false and output something to the user.
Im not looking for someone to write it all for me, i'm simply needing some guidance on the best structure on writing a rails app that is only interfaced with via a URL as well as the easiest method for gather GET values.

Between the 3 comments on the first post i am going to looking into Restful routing and by that gather my params to interact with them.

Related

using rails and an api

I´m mainly a coder but for a project I've got to do some more with RoR. I've been working with RoR for some projects but mainly on the front-end side. I understand it a basic level, but for this project I have to dive in the deep.
What I want to create is an app where a user can search for movies and add them to their account. I want to use theMovieDb api for this, but I can't find a screencast or tutorial that shows the beginning of how to connect your app with someone else's api. So I was hoping the StackOverflow people could point me in the right direction.
This is kind of a big question, but it seems you have two parts here. First is how to make a request from inside your application. The second is how to interact with an API.
I've set up somethings similar where I had to make API requests from inside a controller using Net::HTTP. The answer to this question helped a lot. From inside the controller, I processed the request response as needed, i.e. putting it into a relational database, or displaying it to the user.
How make a HTTP request using Ruby on Rails?
The second part about interacting with the database. The movie database API is described at
http://docs.themoviedb.apiary.io/reference
You need to reference this API documenation. The first thing, for instance, = is they require you to get an API key for instance. You will also need to be aware that they limit the rate at which you can make requests. Without knowing more specifics its hard to give more detail about how to construct the queries.
Hope this helps.

How to use a Google API as my model?

I would like to use the Google Books API as the model for one of the controllers in my Rails app. Basically -I would still like this to act as a scaffold (though I won't be posting to / modifying it)
But I would still like to have a Book object, and be able to do a Book.find([google_book_id]).
What is the best way to go about setting something like this up? Should I generate a scaffold?
Since the Google Books API seems to be a typical REST service, I would start by looking at ActiveResource. It's a way of implementing ActiveRecord-ish models where the data is stored in an external service instead of your database. If you set up a Book model using ActiveResource, you would indeed be able to call Book.find(google_book_id) and have it return a Book object with the properties returned from the API.
Since I've never used ActiveResource myself I can't offer you much advice on the details, but it looks like you would need a way to either use OAuth or add an API key parameter to each request.

Parsing JSON data in Rails Controller

Obviously, this question is a bit Rails beginner question, however it is vital for me.
I'm trying to get multiple variables (more than a single id, parameters like username,versionNo), nothing specific. What I'm trying to understand is, I'm writing the backend of an mobile application, when the client sends me JSON variables with post, in where I should try to serialize it, in order to use it for operations such as database querying. I'm assuming that it will be on controller, but still just want to be sure. Also within pre-defined 7 methods I've assumed that index method would be the most suitable function to do operations like database querying and etc.Since there are multiple parameters, I didn't think show operation would be feasible. But again there are tons of Rails experts in here.
According to CRUD, POST request should be equal to create method in your controller.
Read more here: http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions

trying to build simple web app with Google Maps API

I'm trying to build a simple web app using the Google Map API. I haven't decided if I want to use Rails or Django yet. I've been looking for some tutorials, but none have given me really what I'm looking for. Understand, I'm a newbie when it comes to both Rails and Django.
What I want to do is like this:
http://durasupreme.com/dealer-locator
Where you type in a zip code and it returns a map with pins for the locations on a map. I already have the database information, I'm just wondering what the best way to do this. I feel like I have the idea, I know the tools I need to use, but I don't know how to put it all together.
Any help or links to resources would be greatly appreciated.
D
Here are a few useful links if you decide to go for Rails:
Geocoder
Railscast about Geocoder
Google Maps for Rails
What you are trying to do doesn't have much to do with Django or Rails. It will be mostly javascript. Here's a simple implementation outline:
Follow the tutorials to get started on google maps api on a static local html file.
In javascript write a map_init and add_marker helper functions.
When confident, add the link, div, and script tags you wrote to your template.
Have your view/controller method get a list of objects from the db.
Pass them to the template
In the template do a for loop over the object list.
inside the loop use the appropriate obj attributes to feed the add_marker helper function.

Better solution than accessing routes in the Model?

So I know that you shouldn't use UrlWriter methods in a model, but I wasn't sure what a better way to handle my current situation is.
Basically, I want to allow a User to post something to his facebook feed, and want to write a post_to_fb_feed(object) method in class User. Now, the URL of what is actually posted depends on the object, so I also have a to_fb_feed_item method on the object classes that a user can post. The to_fb_feed_item method just returns a hash that the Facebook API expects, including the url the post should link to.
I've gotten this to work currently, by including ActionController:UrlWriter in my models, but I was wondering if anybody had a better suggestion for how to handle this.
Thanks!
Eric
including ActionController:UrlWriter is the best way to handle it. I don't know why it's not easier to generate urls from arbitrary places in Rails -- sure it might be more common for the appropriate place to be in controllers and views, but the fact of the matter is many models validly deal with urls as data, and need to generate them.

Resources