create a web service in RoR to access DB

48 views
Skip to first unread message

PC Leung

unread,
May 17, 2013, 10:49:10 AM5/17/13
to hk...@googlegroups.com
Hi All

Is anyone working on creating a web service in RoR?

how to create a web service in RoR to access database?

so that it can be called by an Android App?

anyone can give me a guidance?

thanks in advance

Aaron Valade

unread,
May 17, 2013, 10:53:56 AM5/17/13
to hk...@googlegroups.com
Check out the rails-api project [1] and watch the rails-api RailsCast [2]

- A

--
You received this message because you are subscribed to the Google Groups "Hong Kong Ruby on Rails" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hkror+un...@googlegroups.com.
To post to this group, send email to hk...@googlegroups.com.
Visit this group at http://groups.google.com/group/hkror?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


Francis Chong

unread,
May 17, 2013, 11:15:09 AM5/17/13
to hk...@googlegroups.com
Unless you already have a rails site, you might want to consider using a simpler framework like Sinatra. 

Sent from Mailbox for iPhone

Greg Moreno

unread,
May 17, 2013, 11:18:16 AM5/17/13
to hk...@googlegroups.com
Also take a look at grape  https://github.com/intridea/grape
--
http://gregmoreno.ca
http://www.linkedin.com/in/gregmoreno
http://github.com/gregmoreno
http://twitter.com/gregmoreno

"I'm not a great programmer, I'm just a good programmer with great habits."
- Kent Beck

PC Leung

unread,
May 17, 2013, 11:21:27 AM5/17/13
to hk...@googlegroups.com

Any code sample of web service built by sinatra ? Can it be called by JSON ?
Is it popular?
Thanks

Matthew Rudy Jacobs

unread,
May 17, 2013, 11:35:23 AM5/17/13
to hk...@googlegroups.com

Francis Chong

unread,
May 17, 2013, 12:22:41 PM5/17/13
to hk...@googlegroups.com
Matthew, use lmgtfy.com next time ;)

Sent from Mailbox for iPhone


Matthew Rudy Jacobs

unread,
May 17, 2013, 12:24:05 PM5/17/13
to hk...@googlegroups.com
yeah, I have to avoid being too rude
:)

Paul Gresham

unread,
May 17, 2013, 7:35:55 PM5/17/13
to hk...@googlegroups.com
It's already built into rails. If you're using rails3 and you have a model (lets say you have User) you can simply try localhost:3000/users.json and you will get a json response. If you have a user with ID = 5 then you can use localhost:3000/users/5.json

You can also use Curl or a similar tool to test. With Curl you can POST, UPDATE and DELETE. Have a look for RESTful interfaces. 

To know if json will work with your controller, you should see something like this in apps/controllers/user_controller.rb



  def show
    @user = User.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @user }
    end
  end

PC Leung

unread,
May 17, 2013, 10:43:10 PM5/17/13
to hk...@googlegroups.com
many thanks. 

In android, the app captures username and password,
then JSON in RoR returns a code to check login successfulness.

can the JSON in rails provide a login service?

how can the JSON in rails return a code (e.g. 0 or 1) ? thanks

Steve Holmes

unread,
May 17, 2013, 10:50:06 PM5/17/13
to hk...@googlegroups.com
Hi PC

These questions are really basic and many answers can be found on google.
Can I suggest you join the General Assembly Ruby training course? Which should give you a good grounding.
Or consider hiring someone who has coding experience?

If you wish to code web stuff in ruby, you really need to get a grasp of the basics and sending multiple questions on basic things to the list is not the way to progress.

Cheers
Steve

David Lawton

unread,
May 18, 2013, 4:38:12 AM5/18/13
to hk...@googlegroups.com
Well said. 

Much better than what my response was about to be.....
"I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage

David Lawton

unread,
May 18, 2013, 4:42:18 AM5/18/13
to hk...@googlegroups.com
As for the clear text username and password....


Please google for API security and best practices also. 
"I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage
Reply all
Reply to author
Forward
0 new messages