is there a backend for recline.js built to work with rails? - ruby-on-rails-3

Recline.js seems a great tool to display data on grids, maps, etc.
I'd like to use the grid views, but to be able to save what is displayed to the user on a database. I'm currently using rails for this project.
In the docs, they say how to code a backend to integrate with it (http://okfnlabs.org/recline/docs/backends.html) but i wonder if there's already someone working on it ( I couldn't find it on the web)
Thanks

The Backend object in Recline.js a javascript component that talks to a data source of some kind, typically a web service. The Backend component talks to the interface of that web service, and it doesn't care whether it be programmed in Ruby, COBOL or Java, as long as it knows where to get and send the data, and in what format.
So in short there isn't, and can't really be a ready Rails backend, because the implementation depends more on the specifics of your application -- how to map the data in your database (MySQL?) to a service API Recline can understand, and vice versa.

You can use SOLR with Rails, so I dont know why you couldn't utilize the Recline.js SOLR functionality to search your rails data.

Related

Basic iOS Networking Questions

I am trying to do my first App which is a basic joke app that uses tableViews and allows users to add their own jokes to the app database. My problem is in the networking department and I think I'm getting confused with all that is out there. I have a couple basic questions that I was hoping to get answers or opinions on:
I am really confused about the path that is taken from the app on the iphone to the database that is holding the data. Does the tableview controller call a AFNetworking object, that then sends a JSON object to a server-side script(??), that then queries a SQL database and returns the data? I am just looking for a basic path that allows the user to add their own joke to the database.
Is this a URL request? When I see URL request I think of a web page.
I have a website that is hosted on GoDaddy.com. Is this also sufficient to hold the database for the jokes on the iOS app?
I have been searching for days and have gotten no simple answer. I just want to study the correct subjects instead of wasting time. ANY help or pointers would be appreciated.
You have two forms of storage here - some form of web store (such as a server database technology like MySQL) and the local iOS CoreData (if you want to store locally, or make a new request every time thus requiring a connection). You can use web requests (perhaps using the AFNetworking library) to ensure that the local store and the online store match. A typical flow could be for example - on app launch perform a GET request to pull all jokes from the server using a service URL that returns a JSON file, then update Coredata. To upload a new joke, use a POST request which performs a similar function.
A 'URL request' maps to a web technology which uses some form of logic to determine how to return some data. For example, the request may arrive at a web server (such as Apache) which routes your request to a PHP controller file which then talks with the database and returns your data.
GoDaddy is a hosting platform that supports PHP and MySQL (amongst other technologies that will do the same trick), so yes.
In your situation, I would study the Model-View-Controller design pattern. Your app will be a great learning experience I think, you should pick up a lot of core concepts.
EDIT to answer your question in the first comment:
Your question:
1. Are JSON files stored on the device or the server? 2. Does JSON replace JavaScript?
Answers:
JSON is short for JavaScript Object Notation, it's just a way of representing data and doesn't replace anything. It's particularly useful because most languages support parsing JSON in a way that the technology understands. It's a handy way of sending data around because it's pretty lightweight and is widely supported.
In a case like this, the JSON would probably not be stored on the server. The data would be stored in a database. Your request will be mapped to a server side technology such as PHP or Ruby which will then ask the database for the information, convert it to JSON for sending and return it to the client. (It is possible to store data on a server in a JSON file, but you would have to write your server side code to manipulate the JSON file directly, it would be hard work and way less elegant!)
The client (in this case an iOS device) will parse the JSON into an object that Objective-C can play with, like an NSDictionary.
Hope that helps!

Integrating Ember with Express JS

I am aiming to build a project using the Express.Js engine and ember.js for the MVC structure.
I would like to know if anyone has any tips, or links to resources that can help me with setting up the file structure and how to integrate routing with the MVC.
We are using ember/express/node backed by riak, and in our solution the ember.js app will be talking to the express REST server. We're using this: https://github.com/nathanaschbacher/chinood
Basically the ember app downloads once and runs entirely in the client's browser, making api requests for data (from your express app) whenever needed. You can read about how ember data works here:
https://github.com/emberjs/data
Depending on what data store you are using, you'll most likely need to have some representation of your models in both the express app and the ember app. Ember presents the models in a relational way, so the models that are built in the express app may be a bit different depending on the way you're actually storing the data.
Also, we're using iridium to keep our files separate and the project organized. Here's a link:
https://github.com/radiumsoftware/iridium/
You can also have a look at Charles Jolley's convoy, which really nice integrates with Node (Better than Iridium, allowing you to easily share code [models, ...] between server & client sides).
(Sorry for the delay, but I think I finally come back with a good news :-)

What is the difference between ActiveResource and ActiveModel?

As a preface to this question: I am brand new to Rails development (and web-development in general), and some of my concerns may be unfounded, so any feedback would be very helpful.
I am attempting to make a Rails application that plugs into a RESTful API. I have been trying to determine the best way to go about this, and from what I understand, its narrowed down to making my own model from the ground up, utilizing ActiveModel, or utilizing ActiveResource.
It is unclear to me the advantages/disadvantages of each, and to be frank, I do not yet fully understand the difference between ActiveModel and ActiveResource. Can somebody provide me with insight regarding these three options and what makes the most 'sense' in a ror context? Thanks!
The best answer wouldn't just say "Use ActiveModel", or "Use ActiveResource" with instructions on doing so, however that would be helpful as well. I would really appreciate an answer explaining why I should use that thing, etc.
A few constraints I am dealing with are that I need to be using a key when I call the API, and a good number of the API calls will contain additional parameters.
So the key to choosing which package to use here is whether:
You are RETRIEVING data from the web API and want to
store/manipulate on YOUR server, or
You are MANIPULATING data via the web API and don't intend on storing anything on your server.
If #1, you'll need ActiveRecord, as it's Rails' package for manipulation and storage of data on your Postgres/MySQL/etc database.
If #2, you can use ActiveResource exclusively, which will let you retrieve data from the web API, work with it at runtime, and then make changes by posting back to the web API.
Many applications though, will often use both of these packages. ActiveResource to grab data very easily, and then applying it to ActiveRecord models (like User, or Location, etc) which you can use locally without having to grab data from the API over and over again.
To give you an example, for a service I was working on I grabbed Geolocation data from a public source (looking up coordinates for zipcodes), I then saved that data to local Location objects using ActiveRecord so I could look them up repeatedly without the delay of the Web API call. (if you're smart, you'll refresh this data from the web API from time to time)
Determining whether ActiveResource will work for you
Do the service requests conform to the documentation protocol? Look at the Expects a response of block in the Find method, for example. If so, you might be good to go without extra work.
Note: The documentation is a little out of sync with the changelog — as of Rails 3.1:
The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class. eg.
Also, ActiveResource has been removed entirely from the Rails 4.0 branch, so if you're looking forward to starting a new rails application and want the latest and greatest, this isn't an option at all — but all hope is not lost, there are plenty of gems that make interacting with RESTful interfaces simpler, like Faraday (full disclosure: I have not used faraday myself so can really comment on its efficacy, but I located it here, and there are a number of other options.
Note (from the same link above): Active Resource is built on a standard XML format for requesting and submitting resources over HTTP. It mirrors the RESTful routing built into Action Controller but will also work with any other REST service that properly implements the protocol. REST uses HTTP, but unlike “typical” web applications, it makes use of all the verbs available in the HTTP specification.
If the answer to the above is no (it does not conform) you'll need to write a wrapper class, see Facebooker for an example of how this is done in an actively maintained gem.
References:
Great tutorial on ActiveResource
Getting started with ActiveRecord
Keep in mind if you're just starting web development, you'll need to understand database and model basics too — you have your work cut out for you. :)
I will give it a try, and hopefully others will come and correct (or add) to it, so a better picture will exist ...
I see the following main differences between the two:
ActiceResource provides an interface to a resource that is (normally) accessible remotely by a (Rails) RESTful API. It is not stored kept locally, but read, updated, created and deleted by the API only. As Ryan Bates states it: "ActiveResource allows you to easily communicate between multiple Rails applications."
ActiveRecord (or nowadays ActiveModel) stores its record (or model) in a database locally, and allows others to access it remotely by a web interface for
Showing pages
Returning JSON maps or
Returning XML structures
Advantages and Disadvantages
To use ActiveResource, you have to check that your local Rails app can speak to the remote application, so that the RESTful API is compatible.
If both options are free to choose, here are some arguments:
ActiveResource will normally more expensive (calling a remote system costs at least more time) than ActiveModel.
ActiveModel will cost your own resources (setup of database at least), but this is normally not a burden.
So at the end, it depends on if you want to store something (ActiveModel) or only retrieve something (ActiveResource), which means you will use ActiveResource and (perhaps) ActiveMiodel.

Android MySQL php+JSON alternative

I have written a simple database driven app in C# which uses a 2 table MySQL database. This is all a learning curve for me (except c#, which I am now comfortable with)
The app is small, has a couple of datagridviews, uses a few sql select/inserts statments to populate the datagridviews and also update records.
I want to port this app to Android. All of the internet sources I can find recommend a middle php sript which accepts http requests in order to fetch the data from MySQL and then return the results back to the android device where it is parsed with JSON etc etc.
This method is a little out of my reach since I dont have php experience, all of my attempts to implement the php layer have failed, speciially the android app was not receiving any data back, I'm assuming I messed up somewhere inside the php file.
Is there an easier (more noobproof) way to interact with the MySQL database from within android which doesnt require the need for php + JSON? Any ideas are appreciated, thank you in advance.
If you are comfortable with C#, why not use ASP.Net MVC for the middle man?
MVC is especially easy to deal with JSON, and you actually only need to create those "controllers" (as models should already be there from your existing app, and JSON don't need the View to display).
You can create a Web Service with C# that handles the data retrieval from the database; no need to go with PHP. Try create one with WCF API (check this question in order to create one). In order to create an Android client that consumes JSON on Android check this link.
If your mobile application have to access a database over the network you should indeed build a web service fronted to the database.
By putting a web access layer on top of the database you can expose the required queries in an abstracted, secure and convenient manner.
Though this sort of web service architecture can be implemented with PHP + JSON other technologies can be used as well. If you feel more comfortable with C# you can use it to build the web service instead. By doing so you may even be able to reuse some of the code from your existing application.
Actually, it would be better to take php in middle of android & mysql, due to the security concern and by the way this is the most easiest & comfortable method. here is link link. I hope you like it.

Mysql and Dojo Connection

Is there any way to connect mysql database with dojo web pages. Kindly give me some guide lines so that I can make it possible.
Dojo is a Javascript toolkit. When running in the browser, you will need some sort of adapter on the server to communicate with a sql database, usually through some sort of abstraction. It's considered bad practice to do anything which would pass through sql requests from client javascript code for security and probably for other reasons. Very often, a simple "web service" (servlet, php script, etc.) would service requests, read from the database and emit data to the client over HTTP in JSON, XML or some other format.
That said, Dojo does provide some abstractions beyond that. dojo.data provides an API for data access from Javascript which abstracts the data source, and it is used by various Dojo widgets including the dojox.grid. Take a look at QueryReadStore which comes with a sample PHP implementation.
AFAIK not without any serverside component (Servlet, PHP etc.)