Rails using fire-base - ruby-on-rails

I have problem during using fire-base with rails to making a real time form in rails with fire-base how it will be done .. please help me i am new in fire-base.
How to make a real time sharing form in Rails using fire-base.
sorry for bad English ;)

It would be good if you can use ids as keys for each of your form element like input ,select etc and can place value for the element to make each key-value pairs.
This would be effective in a case when you have a persistent record for that form i.e for make new records this approach is not good.

You can use the firebase-rails gem, it's description reads as follows: Ruby
wrapper for the Firebase REST API.
Changes are sent to all subscribed clients automatically, so you can
update your clients in realtime from the backend.
It's very easy to use, although the documentation is somewhat lack luster for but it's just enough for a simple app (if you don't know what you're doing).

Related

Building Zapier App - Updating User With Custom Fields

I have been building out a Zapier app for my company and all has been going well and I am pretty much finished except for one thing I can't figure out which I am hoping someone can help me with.
Using Zapier Salesforce App as an example that is similar to what I am trying to achieve). Imagine I am trying to update a contact. If I do this is Zapier SFDC app it pulls in all the possible fields on that record which can be completely different due to custom fields.
I am essentially trying to mimic this for updating users in our system but cannot pull in the fields that are available to update for that specific user. I am guessing you use the 'Dynamic Field' feature maybe but I just don't see how it can work which may be down to a lack of something on our end.
Anybody run through this sort of experience before that could offer any inisghts? Thanks!
Yes, you need to implement dynamic custom fields in your app. Here is the documentation: https://zapier.github.io/zapier-platform/#customdynamic-fields

Ruby on Rails. Using Google Client API to parse emails

I am new to Ruby and have a question about how to do a specific task on Rails.
I have a list of inventory and each item has a specific Stock ID that is emailed to my personal Gmail account. I want my web application to listen for emails from a specific email account. When my gmail receives an email from that specific account I want my application to parse it for a couple of fields and insert the stock ID into my database.
For example:
Let's say my database has an item with style code: A5U31 and size:10.
The email will say something like item with style code: A5U31 and size:10 has Stock ID:329193020.
I want my Rails application to search the database for an entry with that specific style code and size, and when it finds an entry to simply insert the stock ID into the row.
I am trying to using the Google-API-Client gem to this, but I am struggling, because I am still a beginner. So far I have done this quick-start guide to authenticate my gmail account with my rails app.
https://developers.google.com/gmail/api/quickstart/ruby?authuser=2
If someone could help me figure out how to write this sort of code and where to put it in my app(models, controllers, views) that would be very appreciated. Thanks!
I know it's been several months since you posted this, so you probably already have it worked out, but in case you still need a solution (or if someone else wants to do something similar), I'll share my thoughts:
At a high level, it sounds like your plan is
Identify when a new email has come in (either by polling or by using a push notification).
Grab the new email's content.
Parse the email's content in order to extract relevant data.
Use the data to query and update a database.
Based on the documentation for the Gmail API, it does look like you should be able to set up push notifications, so you won't have to poll the endpoint to get the information you need.
However, my big takeaway from this list is that none of the items on it really require Rails, since you're not exposing an external web API for requests. I suppose that you could leverage ActiveRecord to create an item model and use that to manage the database; however, since it seems like you'd only need to make some basic SQL queries (and the same ones each time), I'm not sure that bringing in ActiveRecord adds much value.
If I were trying to solve this problem myself, I would probably create a simple Ruby program that (a) uses the gem you mentioned to handle push notifications from the Gmail API, and (b) uses another gem to connect to whatever kind of database you're using (e.g. pg for Postgres) and make the necessary queries.
(All of this assumes, of course, that you aren't specifically using Rails for some other reason, e.g. adding this feature to an existing Rails application).

Local storage on Rails

I've built a Rails app, basically a CRUD app for memos/notes.
A notes title must be unique. If a user enters a name already taken a warning message is shown prompting them to chose another.
My question is how to make this latency for this feedback as close to zero as possible. When creating a note little UX speed bumps like this will get annoying for user quickly.
Of course the main bottleneck is the network. Inspired by Meteor (and mini-mongo) I was thinking some kind of local storage could be a solution?
I.E. When app first loads, send ALL JSON to the client with ALL note titles. The app (front end is Angular JS) could check LocalStorage (or App Cache, Web SQL?) instead of incurring a network round trip. The feedback would be instant.
I've used LocalStorage in the past to augment an app, but in the scenario it'd really seriously depend on it. I'm not sure how confident I'd be building on something that user might not have. Also as the number of user Notes/Memos I have doubts how feasible it is to send a JSON object down the wire with ALL the note titles. That might get pretty big. On the other hand MeteorJS seems to do this with no probs.
Has anyone done something similar or have any pointers? Thanks!
I don't know how Meteor works here, but you're right that storing all note titles in localStorage is not a good idea. Actually, you don't need localStorage here, you can just put it in a JS array, because you need this data only once (when checking new note title).
I think, there could be 2 possible solutions:
You can change your business requirements and allow non-unique title. Is there really a necessity for titles to be unique?
You can verify note title when user submits form. In this case you can provide suggestions for users, so they not spend time guessing vacant title.
Or, if titles must be unique only within a user (two users can have same title for their notes), you can really load all note titles in JS array and check uniqueness while users types in a title.
Or you can send an AJAX request checking title uniqueness as soon as user finished typing the title. In this case you can win some seconds.
Or you can send an AJAX request as soon as user typed in 3 symbols. The request will return all titles that begin with these 3 symbols, so you don't need to load all the titles.

Store ruby Mail (from gem) object in ActiveRecord

I'm currently implementing a very basic IMAP client into an application I'm building in Rails. I'm using the Mail gem which supplies lots of useful ways of parsing the imap data.
I'd like to store the Mail object that it's generating in the database. Is that possible?
i.e.
email = Email.new
email.uid = id
email.mail = Mail.new(imap.fetch(id, "RFC822")[0]["attr"]["RFC822"]
email.save
It's a convenience thing where I don't want to have to download the object again unless I have to since performance on the IMAP call is slow, but I'd like to be able to have it there to look back on (and do any breaking down I needed to later).
I could then call
email.find(x).mail.body
and various other useful things without having to build out that functionality in my own email model.
Q1: How would I set up the active record model?
Q1a: Would I be better off doing something that excluded the attachments to make it an easier object to store? (is that even possible?)
Appreciate your help,
Several database schemata have been developed to store mail. I've worked on one, and there are others. Believe me, it's hard work. The result can be very useful, but since your question doesn't focus on the result I suspect it's not worthwhile in your case.
You might find it easier to use a json library to write your object graph to a file with an automatically inferred structure, as most json libraries seem to support these days. That won't let you do as much, but it's very much easier and lets you store both completely and incompletely retrieved messages. If you haven't fetched a particular body part, the json library will just write a null for that field.
It depends on what you want to do with the stored mails. If you need only specific parts of the mail to be easily accessible trough the database you won't need a complex setup like archiveopteryx, which basically maps a complete representation of emails to relational database tables. In most cases though you won't need that much detail and it will be totally perfect to use a simple data model.
A1: rails g model Email from to subject date:datetime message_id body. this are just the basic parts, should get you started.
A1a: You don't need to store the attachments if you don't want to. If you need them, you'll probably be better off not storing them in the database itself. Attachments are just like uploads so there are plenty of gems that can help you do that (https://www.ruby-toolbox.com/categories/rails_file_uploads).
Using posgres jsonb columns, you can store the email as json, in my case I disregard the attachments (which I store the reference to and retrieve as and when required).
This works pretty well with the Mail gem.

Updating a Passbook Pass using Ruby on Rails or an alternative?

I was wondering how I would go about updating my passes. I already know I need a webServiceURL (which I assume will be your IP address or one set on Ruby on Rails or something) and an authentication token. I'm more focused on how I would actually, physically update it. Is there an easy way out of this? Sort of like those iPhone app creating websites (but you don't professionally code it). I'm going to look into it more, but there aren't too many resources on the internet to choose from (that are useful).
If you are looking for a WYSIWYG, point and click solution, you might want to check out our service PassKit.
To see how updates work, you can start with this demo pass, flip it over and push yourself an update. You can import the template for the demo direct into the pass creator, edit it, and be pushing updates to your own passes within 5 minutes.
We also have a fully functional API that allows your to update and push a new pass your pass in a single call, E.g.
https://api.passkit.com/v1/pass/update/template/yourTemplateName/serial/yourPassSerial/push/?field_value1=newValue&field_value2=newValue2
If you want some code to get you stated, you can also access the source code to our pass creation pages.
If you are going to roll your own, I would use passbook-ios or something like that which is a Ruby Gem. If you want to use a service Urban Airship has one....though the pricing is a bit expensive at 10 cents a pass.
Lance

Resources