Best Way To "Drop In" Dynamic Content Into an Existing Static Site - ruby-on-rails

A friend of mine has a static web site. She would like to add a registration form that would allow people to register for classes. Re-creating the web site using ROR or Wordpress or something like is not in scope. We also want the user to use the same domain, regardless of whether he or she is viewing a static or dynamic page.
The least intrusive way that I can think of doing this with CGI, preferably using Ruby. However, I really don't like writing CGI code and I am much more comfortable with frameworks such as Sinatra and ROR.
Is using an advanced framework really even possible for this type of situation? If so, then is it more trouble than it's worth?
Thanks in advance!

If I were you I would do it in Sinatra, and perhaps use a front end like Nginx to redirect to your Sinatra app. So something like:
location /myform{
proxy_pass myserver:6000;
}
Where your Sinatra is running on port 6000. Sinatra is very simple and you can probably do this in a short time. ROR I think is a bit heavy for this. We do things like this all the time for special needs/shared apps, even when they are already dynamic.

You can develop an app that injects the dynamic code into her static site via Javascript. I do that for one of my projects here at work and it seems to be an acceptable solution.
A quick HTML sample:
<!doctype html>
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="loader.js"></script>
</head>
<body>
<div id="customcontent" class="contentlib"></div>
</body>
loader.js:
$().ready(function () {
$('<style type="text/css"> ... </style>').appendTo('head');
$('.contentlib').each(function() {
$.getScript($(this).attr('id')+'.js');
});
});
customcontent.js:
$().ready(function () {
$('#customcontent').html(' ... ');
});
This is a bit more complicated than it has to be (the second script load based on the div's id) since I have to support multiple replacement on the same page.
Anyway, I could see you using this to inject your app from a 3rd-party website and, as long as you stuck to using AJAX form submissions, the average user would be none the wiser.

Related

How to write w3c-conform Angular-Material applications?

I am writing a web application using AngularJS and Angular Material. I'd like to write valid HTML code (according to the w3c-validator).
I already know that I can write valid AngularJS directives like this:
<body data-ng-app="myApplication" data-ng-cloak>
However, AngularJS uses a lot of custom tags, such as:
<md-content></md-content>
I already tried several search queries on Duckduckgo, Google, and Stackoverflow but I can't find an answer on how to rewrite these tags in order to create valid HTML code.

Integrating rails & angularjs

I tried Angular, and I liked it. I've began to integrate him into my rails-app, but then appeared some doubts about architecture
Routes. I would like to navigate without refreshing the page, before i used Wiselinks gem, it's easy and cool - just install, patch link_to helper and done. But angular have his own router, and ui-router (which is cool). I want my app to be running at the browser like Opera Mini and IE, but ui-router doesn't have such callbacks as in wiselinks. I wouldn't create mobile site version - the design is adaptive yet. It means, I would use rails routing, but I want to AJAX page refreshing when it can be (progressive enchansement, yep). What do I do?
In many places, the content is rendered by Angular, i.e. a list of posts (by ajaxing json). That fast & cool on desktop, but again old browsers! I need to render it on server for them. Or I haven't?
I'm stuck. Thanks.
This would be best trip to angularjs + rails 4...
This post clear my doubts and now i m very clear about architecture, routes, controllers, model, etc..
http://www.honeybadger.io/blog/2013/12/11/beginners-guide-to-angular-js-rails
I hope this solves your DOUBTs
and to know further about angularjs visit
http://www.angularjs.org
It's not necessary that you have to use angular routing. You can use ng-controller directive to inject controllers in your view.
Angular in general is very fast. I have been using it even in mobile browsers, it works like a charm. True if do heavy $scope manipulation, things might get little slow.
Talking about old browser support, till IE8, you are pretty good, if you follow http://docs.angularjs.org/guide/ie as already mentioned by shaunhusain, but below that I am skeptical.
I wouldnt recommend using wiselinks alongside with angular. We have tried that in a production app and it took us a long time to make this work, there had been so many issues with undead scopes and other artifacts.
Therefore, we have ended up throwing out wiselinks and replacing it with a similar directive written in angular. This way its easier to avoid problems when destroying or compiling dom.

How to make some of my web pages searchable in my project

In my website i am including user to add blogs. How can i make those blogs searchable in google. I want to make only the blogs searchable. But i don't want to make remaining pages searchable. How can i do this.
Regards
On all pages except the blog pages, add the following to your HTML <head> element:
<meta name="robots" content="noindex">
This will prevent search engines from indexing the page.
Using javascript/jquery isn't an option as this is client scripting, which the bots won't read.

good example applications combining rails 3 and sproutcore

I am trying to write a sproutcore frontend for a rails 3.1 application I am making. I have had a look at the sproutcore guides, but I am interested in seeing real examples how to use sproutcore together with rails 3(.1).
I have found two examples, but each is totally different:
A todo-app created using bulk_api: an interesting approach using a specific REST-style to minimise the traffic. But it proposes to place the sproutcore app in app/sproutcore, and is still a bit unclear to me how that actually hooks in completely.
Travis-ci which seems to be a very clean example, rails 3.1, to use sproutcore. It is not yet completely clear to me, but all sproutcore js is cleanly stored inside app/assets/javascript/apps and as far as i can tell, the application.html just loads the js and provides the frame where everything is loaded into.
Do you know any other examples? How do you use sproutcore in your rails app?
The method you describe is the same way that you integrate backbone.js into a rails app, and it seems to work very well
https://github.com/codebrew/backbone-rails
This stores backbone in
app/assets/javascripts/backbone/
app/assets/javascripts/backbone/app/models
app/assets/javascripts/backbone/app/controllers
And then there is a script tag in the view that just initializes backbone
<script type="text/javascript">
$(function() {
// Blog is the app name
window.router = new Blog.Routers.PostsRouter({posts: <%= #posts.to_json.html_safe -%>});
Backbone.history.start();
});
</script>
I imagine a similar process for sproutcore would make sense
I did find a demo-project: sproutcore-on-rails that did manage to make things clearer for me.

Anyone developed an App with a Flex UI and Rails backend?

i am looking into the possibilities of doing some work for a client on Flex with a Rails backend.
It ain't rocket science however i was wondering if anyone out there had some experiences with these two AWESOME technologies?
Thanks in advance....
Peter Armstrong has written an excellent book called Flexible Rails, and has also created a Flex/Rails framework called Ruboss. I recommend you check out both of these resources.
I have developed a few application using Flex and Rails. The easiest way is just to use the as3corelib (http://code.google.com/p/as3corelib/) and use standard JSON objects. You can play around with the AMF serializers, but none of them are production ready (they are written in ruby and not C).
The biggest thing you need to make sure of is if you are creating resources from Flex you need to send the authenticity key from flex. I do this by writing a helper to output it to a view:
<script language="Javascript">
function getAuthKey() { return "<%= form_authenticity_token %>"; }
</script>
Then use ExternalInterface to call it inside Flex.
ExternalInterface.call('getAuthKey')

Resources