how to create web service Api in rails 4? - ruby-on-rails

can anyone help me how to create a web service API in rails 4. I know how create web service API in ruby 1.8.7 and rails 2.3.5 with action web service gem. When I am trying to use https://github.com/datanoise/actionwebservice gem in rails 4, I am getting deprecated errors.I want to upgrade my web service app. Please help me.

Rails-API looks promising, because it will be part of Rails core in Rails 5.
Rails-API
Rails-API is a subset of a normal Rails application, because API only applications don't require all functionality that a complete Rails application provides. so, it compatible well with old Rails versions. I don't know compatibility exactly, but I'm using it with Rails 3.2.x
There are another proper framework for this purpose, for example, Sinatra, Grape, but If you familiar with Rails, Rails-API will be the best choice.

Actionwebservice is long deprecated, in favour of REST API's. At my previous job we used a fork of actionwebservice in a rails 3 project.
Since there is no maintainer anymore for the actionwebservice gem, that fork never got merged back. If you check the fork history, a lot of people are fixing and partially updating it, but it is scattered all over the place.
Afaik none of the forks were updated to use rails 4. But using a rails 3 fork might just work.
If you really need to build a SOAP API server with Rails, imho your best option is to take a look at Wash-out, but you will have to re-write your API code.

Related

How do I do api in Rails 4? Rails-api gem is merged in Rails 5

I already have a Rails 4 website.
Now I'm building a mobile app and need to get data from the the same database my website is using.
It looks like rails-api gem is merged in Rails 5. But Rails 5 is not production-ready yet and is not supported by such gems as devise.
Docs are all on merged version:
http://edgeguides.rubyonrails.org/api_app.html
So which gem and guide should I use to create an api for my website at the moment?
There's nothing in Rails 4 that prevents you from building an API. Why not create an API in your existing Rails app under a namespace? There are some gems like Grape that can help, but they're not necessary. There are many tutorials on the topic including some Rails Casts that are still relevant, so it should be easy.
The Rails API gem is a lighter version of Rails that is stripped down to only the core parts that an API app needs. This means you don't have ActionView or server generated templates. It's basically Rails minus anything that an API doesn't need.
By being merged into Rails 5, it simply means that Rails 5 will give you the option to create a stripped-down app that only has what an API app needs (minus ActionView and other cruft).
But everything inside of Rails API is inside Rails and more.
But since you already have a Rails app running, just build the API into it. If you want to create an API only app, then go ahead and create one using either the Rails API gem, a normal Rails app, or even Sinatra.
You can create an api on your own without any gem doing api. Try to follow some examples like: Building a RESTful API in a Rails Application and others.

The rails way of doing client side validation (Rails 4 with simple_form)

I am new to Rails and using Rails 4. I have started some forms for creating/editing some models and have added some validation which works fine on the server side.
I assumed that Rails would have something built in to handle client side validation - turns out it doesn't.
I have searched on google and found 'client_side_validation' which is no longer maintained and I don't think works in Rails 4 anyway.
There doesn't seem to be an obvious go to library for Rails client side validation. So what is the 'Rails way' of handling this? Roll your own? Duplicate the logic client side using jQuery? Use html5 validation and fall back to server side when it isn't their? Or is there a library (preferably one that works with simple_form) that I can just install and use?
There is client_side_validations, but is not longer maintained. Probably the best way is using some jQuery plugin like jquery-validation.
Rails 4 + Simple form : To install "Client side validations" with simple_form successfully, you should check for latest versions direct from Github with latest branch.
The released gems don't work with Rails >= 4.0
gem 'client_side_validations', github: 'DavyJonesLocker/client_side_validations'
gem 'client_side_validations-simple_form', github: 'DavyJonesLocker/client_side_validations-simple_form'
Make sure your gem file does not use these versions
client-side Validation 3.2.5
client_side_validations-simple_form 2.1.0
These versions does not support rails 4.2.0
For more detail please check this link,
https://github.com/DavyJonesLocker/client_side_validations-simple_form/issues/41
One way to achieve this is in Rails 4 is to use the client side validation gem: http://rubygems.org/gems/rails4_client_side_validations
This guy here is using it: Client Side Validations and Rails4
Railscasts provides a good tutorial (Rails 3) on it here:
http://railscasts.com/episodes/263-client-side-validations
I was able to use a fork of the original client_side_vlaidations that is very active at the moment. I am using the latest version of simple_form, rails 4.1.8, and this client_side_validations. Simple setup with basic config.

JasmineRice on Rails 4

Has anyone tried JasminRice gem with Rails 4?
I've got Ember Rails 4 app and I would like to use Jasmine Rice but I'm not sure whether it would work out well as their Github account says Pain free coffeescript testing under Rails 3.1
Jasmine Rice
I would advice you to use jasmine-gem, which recently gained Rails 4 support. jasmine-gem is developed by Pivotal, the company that develops Jasmine itself, and is actively maintained. While this gem was very basic for a long time, it has improved tremendously, especially with version 2.0.0. Spec execution in Phantomjs (in addition to the browser, which is the fastest for development) is supported, and there is full integration into the Asset Pipeline, which lets you e.g. write tests in CoffeeScript. At my student job, we are using jasmine-gem extensively and are very happy with it.
In the jasminerice installation section they mention that it should work on rails 4:
This gem has been tested and run with Rails 3.1 and 3.2. It should
also run on Rails 4.
"Should" is not as strong of a word as I would like, but I have a ember rails 4 app and jaminerice has not given me any issues.

What should a Rails 3.x noob know about maintaining a Rails 2.3 app?

I recently learned Rails (Rails 3 to be specific) and got a small project maintaining a Rails 2.3.2 app.
So, as you might expect, I keep running into differences between what I learned in Rails 3 and what I'm working in.
For example 'rails server' command in Rails 3 is 'script/server' in Rails 2.x.
What else should I know to maintain my sanity?
If you're new to rails, I don't know if you'll see a lot of differences. The rails server command is one thing however.
The other big thing is the use of .gemspec in Rails 2.3.5 instead of Bundler and Gemfiles in Rails 3. Installing gems/specifying which gems your app uses is way better in Rails 3 I think.
The rest are mostly syntax changes and depreciated functions in specific areas (e.g. javascript generators).
This Blog does a good job of listing most of the major changes in more detail.
Hope that helps!

Rails 3: What is the difference between an Engine and a Gem?

What is the difference between the two and when one should be used instead of the other?
An Engine in rails terminology is a actually a subapplication of a web-application. For instance, something like a blog, a forum, or simple authentication: these are not full-blown applications, but pages/views/controllers/models that can be added to any rails application.
In rails2 this would be done using a plugin. Now since rails3 an engine can be packaged in a gem.
A gem is a ruby library, which can be found on http://rubygems.org and it is the standard (only) way to package and distribute ruby code to other rubyists.
So to conclude:
A gem: is a generic library, which can be easily installed, which are version-managed, have dependencies and such.
An engine: is a sub-application of a Rails application, and since Rails 3 these are distributed as a gem (which is awesome!).
So when will you use one or the other:
create a gem if you want to share ruby-functionality
create an engine (and package it in a gem) if you have parts of your rails application that can be used more generally.
Hope this helps.

Resources