Creating Rails api of already created web application in Rails architecture

116 views
Skip to first unread message

Puneet Agarwal

unread,
Feb 18, 2015, 11:30:03 PM2/18/15
to rails-a...@googlegroups.com
Hi,

I have working rails web application but now I want to have application for mobile also with some less functionalities as compare to  , so I am thinking of creating Rails::api for already existing rails application but in documentation there is way to convert already built rails application to rails api whereas I want rails api along with Rails application.

Can anyone help me please about this, I need to develop Rails::api for mobile.

Thanks.
Puneet

Jean Boussier

unread,
Feb 18, 2015, 11:38:41 PM2/18/15
to Puneet Agarwal, rails-a...@googlegroups.com
Hi Puneet,

There is no real difference between Rails and Rails-api.

Rails API is just a standard Rails but with a few components disabled because they are only really useful for websites.

You simply want to have either a namespace e.g. `/api` or a subdomain e.g. `api.yoursite.com` for your API controllers.

You also probably want to checkout https://github.com/rails-api/active_model_serializers, it’s basically a view layer but to generate JSON.

Hope this helps, good luck.

Puneet Agarwal

unread,
Feb 19, 2015, 7:05:54 AM2/19/15
to Jean Boussier, rails-a...@googlegroups.com
Hi Jean,

I don't want to reduce functionality in website , I just want to implement mobile application also of website and I have created designs and layouts in html and using jquery mobile. But now the main problem occurs in sending data and receiving data from server. How to access controller actions from layouts ?? I just want 3 pages in my mobile application so is there any way by which I can call these actions .  I am going through this api documentation but it is not that clear to proceed.

Thanks for the quick reply.

Carlos Antonio da Silva

unread,
Feb 19, 2015, 7:07:52 AM2/19/15
to Puneet Agarwal, Jean Boussier, rails-a...@googlegroups.com
Puneet, my recommendation based on your comments: forget about the Rails API project, and just use Rails the way you know. What this project does seems totally unrelated to the goal you're trying to achieve, just go Rails all the way down.

Hope that helps.

--
You received this message because you are subscribed to the Google Groups "rails-api-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rails-api-cor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
At.
Carlos Antonio

Puneet Agarwal

unread,
Feb 19, 2015, 7:21:34 AM2/19/15
to Carlos Antonio da Silva, rails-a...@googlegroups.com
Carlos , I am looking for creating mobile application too using the existing methods or with slight modifications . Is this not related to rails api because I just want 3 pages in my mobile application which will make call to controller methods but Rails will not allow without authentication.

Suppose I have created page xyz.html in which I have written ajax call as:-
$.ajax({
            type:"POST",
  dataType:"json",
  data: {'value': 'hello'},
  success:function(result){
    alert(result.status);
        }});
    }

But the above code will simply not work because it will not allow me to access request like this which I have mentioned in url.

Can you please clear my queries if I am wrong at point.

Thanks.

Carlos Antonio da Silva

unread,
Feb 19, 2015, 7:31:21 AM2/19/15
to Puneet Agarwal, rails-a...@googlegroups.com
Have you written any ajax calls on your main site? It's pretty much the same thing, there's nothing different, you must make sure to include jquery-ujs on your layout as you do with the site, and have the csrf helper generate the meta tags for you, so that you can use POST/PUT requests normally through your ajax calls.
--
At.
Carlos Antonio
Reply all
Reply to author
Forward
0 new messages