Advanced Ajax with RoR and jQuery UI - ruby-on-rails-3

I don't have much web development practical experience although I had studied a lot on the web (Treehouse, CodeSchool, other tutorials and articles).
I have found some explanations on how to use Ajax with RoR and jQuery. But I'm having difficulties to understand how to solve my problem as the explanations often use jquery-ujs that I suppose I can't use in my case.
My problem is difficult to explain here but is similar to implementing this shopping cart on RoR, including more parameters like price
The jQuery UI is working for me in my RoR application. What is missing is the AJAX part and how to make it work with RoR
I have found some questions here on StackOverflow that is about this topic but it didn't helped much as they are probably for more advanced users.
So, I believe that the best help would be a tutorial or book or some other reference that is more similar to my problem. However any advice or other kind of directions may help

After struggling a lot, finally I solved my problem.
I will post here the resources and some tricks that helped me. I hope it can help others. StackOverflow didn't let me post all the links. For this reason, I just gave some hints that may help to find some resources.
About the jQuery Ajax concepts, I recommend Code School jquery course "The Return Flight".
The second thing that I think helps is learn to debug. Firebug helped me a log to debug the client side/javascript/Ajax. This link may help on that:
http://www.zyxware.com/articles/2642/debugging-tips-how-to-debug-ajax-requests-using-mozilla-firefox-and-firebug
Since the problem may be to debug RoR. Look for a RailCast on the subject.
One of the things that I took some time is if it would be better to use $.ajax(), $.post(), $.get() or $.getJSON(). The link below may explain better but to sum it up, $.ajax() is the more generic one and the other are simpler ones and that call $.ajax() with specific parameters.
Difference between $.post and $.ajax?
It is important to understand how RoR routing works to call the right url with the right $.ajax() type. "rake routes" may help.
This link may also help to use the right $.ajax() type.
http://old.thoughtsincomputation.com/posts/understanding-rest-in-rails-3
Finally, to send the right format from the javascript to RoR controller, this link may help:
How to send and store data to rails through jquery/ajax as a JSON object?

Related

Does RestSharp API documentation exist?

We're trying to use RestSharp, as it seems to be the preferred software for REST communications. However, there doesn't seem to be any thorough documentation anywhere. The restsharp.org site has a couple of simple examples, and it refers to the GitHub site (https://github.com/restsharp/RestSharp/wiki) for documentation. That covers a lot more, but still not that much. Otherwise, the RestSharp site just links back to StackOverflow.
Is there a good document that describes RestSharp methods and usage in detail? (I'll probably feel like an idiot when someone points out the obvious, but I'm just not seeing it!)
Thanks!

Is it possible to use Aurelia in a non-spa application?

Recently I've been playing around with different frameworks and libraries, looking for something that really suits my needs.
You see, my job mainly involves creating asp.net mvc applications and for most of them using Razor and a little bit of jQuery is enough. But in certain cases and only for a few pages,which are rarely more than one or two per app, I really need something extra that helps me avoid getting entangled in a bunch of jQuery code.
As I mentioned, I tried a couple of alternatives and from them, the one I liked the most is Aurelia, because of its simplicity and the fact that it embraces standards, BUT the more I dive into the framework, the more I think that it might not be what I'm looking for,as it seems more suitable for full spa applications and what I need is:
Something that helps me reduce the amount of DOM manipulation
A efficient templating engine
I know that Aurelia provides that and much more, but I don't want/need a SPA, I need those functionalities ONLY in some specific pages and not the whole application.
Can Aurelia help me achieve this? If so, how?
Sure, Aurelia can help you achieve that. You just won't use certain features like routing in on the pages you create with Aurelia.
That being said, it isn't a drop in replacement for jQuery, but none of the "modern" JS frameworks really are. And you're going to end up spending time learning whichever one you end up choosing.
Check out the aurelia.enhance functionality, it might be just what you're looking for!
I have used Aurelia in a non-SPA context, and it worked out well. I think this is exactly what you describe. For example:
http://legumeinfo.org/chado_phylotree/phytozome_10_2.59028020
https://github.com/legumeinfo/tripal_phylotree/tree/lis_master/theme/js/aurelia
I'm using aurelia for dynamic elements on some sites. Like comments for example. Page loads fast w/o comments.Then Aurelia kicks in and loads the comments below. Also with some signalR magic the discussion is updated in real time. It is awesome and insanely easy.

Does anyone have a SlickGrid wrapper for Haxe?

I am using the Haxe multi-platform programming tool (http://haxe.org) which, among other things, can generate JavaScript output. I would like to know if anyone has already done a "wrapper" library to interface Haxe with SlickGrid.
Doesn't look like one exists yet... sorry!
Unless someone has made one but just not shared it. Could be worth asking on the haxe mailing list / google group? You'll get a wider audience than on stack overflow.
If it looks like no one has done it, you can write your own... it's probably quite do-able. And not too hard either. I'd be happy to help you figure it out as you go... cause I might want to use it one day too :)
If you do decide to take that route I think the best option is to post on the mailing list, and we can help you out from there. There's also a document on the wiki with some instructions:
http://haxe.org/doc/js/extern_libraries
This stuff is always a bit daunting when you first get started, but don't be afraid to ask for help and hopefully you'll be up and running in no time.

Sencha touch app building

I was put in charge of learning this and well I have read and tried to understand it all. I am lost in how to get it started and optimized. I need to achieve a window at startup that is menu based and takes you to different components. I think I have the photo galleries sorted out just now sure how to link to the startup window.
examples
I used this tutorial when I was trying to learn - http://miamicoder.com/2011/writing-a-sencha-touch-mvc-application/
The learning curve is quite steep but once you understand it it's a really good bit of kit to know your way around.
If you don't already understand the MVC (Model View Controller) architecture then it's going to be a bit tricky but the tutorial explains it all pretty well.
My advice would be start following the tutorial. Stick to it, get it working and THEN adapt it.
Good luck.
With Sencha Touch 2, the team have created a bunch of guides which hopefully help ease the pain when trying to learn the framework.
I suggest you first take a look at the Getting Started Guide, and then move onto the Building your first App Guide. These both should give you a kick start on where to start.
After that, I would definitely recommend you take a look at the code of their various examples, and then try modifying it. When I was first learning the framework (and JavaScript in general) I found that taking existing code and modifying it was definitely the easiest way of learning. Obviously this varies from person-to-person, but it is always a good step.
Much of their documentation have previews and examples which you can actually edit the code inline, which I have found very useful in the past. You can view an example of this here.
The Touch Forums are very active. Almost all topics get responded to within hours, and I have never seen a post which was never responded to.

Expose function in ruby on rails

I am looking at a rails app and at the top of every controller there is a block of code that looks something like this
expose(:var) {Model.find params[:var_id]}
I understand what is inside the block just fine but...
I cannot find any documentation on what the expose function does where it comes from or anything I have tried searching the project and using the searchable rails docs.
I would love to know what it does, can someone please tell me or point me to the docs.
This is probably referencing the decent_exposure gem. You can learn more about it here: http://railscasts.com/episodes/259-decent-exposure
Source: https://github.com/voxdolo/decent_exposure
It's a method from the Decent Exposure gem. You can check out a screencast that Ryan Bates did on it over at Railscasts. It's a really great gem. I use it in my application. It cuts down on a lot of the redundancy in the controller layer.
expose is not a part of Rails, it comes from the decent_exposure gem.
It is not an answer to the question. I just want to make the Rails world a bit better and I hope that somebody will read this.
Please think twice before using expose. You should only use it if you 100% sure you are using it the right way and it really makes the code better. Read the documentation properly!
One of projects I worked on became unmaintainable because of tons of expose in controllers which replaced not only all #instance_variables passed to views, but also a lot of business logic and the most helper methods.
When you use expose it is not clear in which controller actions and in which views it is used. Unexperienced developers combine data and logic for multiple actions and multiple views in the same expose block.
That's a nightmare.
Believe me, expose really destroys projects if not used properly.