Topic: Need Help to "setup" a RESTful webservice

Hello all

I open this topic because I'm going to need a little help for rails and Webservices and also because i am a beginner.

I have now need to "build" a webservice that will enable a third party application (mobile application) to connect to a mySQL database server hosted on my ubuntu 10.04 server

So I have already committed some research and asked some questions and it seems that Rails 3.0 can help me materialize my project by creating a RESTful webservice type (that I don't know yet exactly what it is). Anyway, what I have understood is that I could make requests of kind 'http' in my DB via webservice that will return an XML I can parse.

So I have installed on my server ruby 1.8.7 and gem 1.8.21

I have then launched the famous gem install rails and everything seems ok ... I have Rails in its 3.2.3 version

Only now I 've no idea how to "create" my webservice (and where I must put it ? In /var/www/ to be reach from the web ?) Or how to parameter the 'linker' with a mySQL DB.

I have understood by reading different things on internet setting up a RESTful webservice with rails is not to complicate but i really don't find how to setup mine ... that's why i need help ! A lot of tutorials i've seen are too old. And I really would like advices to set it up !

So you have some tips, some ideas, or tips for m 'refer and help me to put all this in place.

Thanks for all !

Last edited by Romain77 (2012-04-03 10:40:49)

Re: Need Help to "setup" a RESTful webservice

Michael Hartl has a great tutorial book online that he keeps updated. Here's the link for the Rails 3.2.x version:
http://ruby.railstutorial.org/ruby-on-r … ersion=3.2

I think it's a good place to start.

Last edited by Brian71 (2012-04-03 11:31:23)

Re: Need Help to "setup" a RESTful webservice

Ok Thanks !

I will look on it !

And i will post here if i have some questions !

Thanks for all

Re: Need Help to "setup" a RESTful webservice

Hi there,

I have a little problem. Actually, i follow up the tutorial as Brian71 suggest me and when i try to launch the rails server as root i have this error :

/usr/lib/ruby/gems/1.8/gems/execjs-1.3.0/lib/execjs/runtimes.rb:50:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
  from /usr/lib/ruby/gems/1.8/gems/execjs-1.3.0/lib/execjs.rb:5
  from /usr/lib/ruby/gems/1.8/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
  from /usr/lib/ruby/gems/1.8/gems/coffee-script-2.2.0/lib/coffee_script.rb:1
  from /usr/lib/ruby/gems/1.8/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
  from /usr/lib/ruby/gems/1.8/gems/coffee-script-2.2.0/lib/coffee-script.rb:1
  from /usr/lib/ruby/gems/1.8/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require'
  from /usr/lib/ruby/gems/1.8/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1
  from /usr/lib/ruby/gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:68:in `require'
  from /usr/lib/ruby/gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:68:in `require'
  from /usr/lib/ruby/gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:66:in `each'
  from /usr/lib/ruby/gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:66:in `require'
  from /usr/lib/ruby/gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `each'
  from /usr/lib/ruby/gems/1.8/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `require'
  from /usr/lib/ruby/gems/1.8/gems/bundler-1.1.3/lib/bundler.rb:119:in `require'
  from /home/romain/Dev/rails_projects/first_app/config/application.rb:7
  from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/commands.rb:53:in `require'
  from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/commands.rb:53
  from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/commands.rb:50:in `tap'
  from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/commands.rb:50
  from script/rails:6:in `require'
  from script/rails:6

It is pretty weird beacause i have install ruby 1.9.3 via RVM but when i type

ruby -v

I have this answer :

ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]

So why my version of ruby hasn't been upgrade by RVM (ruby 1.8.7 was already installed on my system)

And the other problem is the problem of "execjs" !

i have run

 gem install execjs

but i still have the

/usr/lib/ruby/gems/1.8/gems/execjs-1.3.0/lib/execjs/runtimes.rb:50:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)

Maybe this problem "exists" beacause the ruby version ???

I still block ... so thanks for help !

PS : To be sure i have download the ruby 1.9.3 p125 and install it manually but i still have the 1.8.7 version of ruby on my system ... Seems to be "blocked"

Last edited by Romain77 (2012-04-03 14:21:26)

Re: Need Help to "setup" a RESTful webservice

You probably have Ruby 1.8.7 installed as default. To switch to Ruby 1.9.3 type:

rvm use 1.9.3

Then you need to add a javascript gem to your gemfile. Look in the root directory for your application and you should see a file called .gemfile (you should have editted it as part of the tutorial). Add this to your gemfile:

gem 'therubyracer', '>= 0.9.2'

That should fix the java issue. Don't know why that's not covered by Hartl's tutorial, but I think it should be.

By the way, the link below takes you to a website that's got a pretty good explanation about how to use rvm. Pay particular attention to the part about creating a .rvmrc file for your project. The rvmrc file will automatically set the Ruby file and gemset for each project when you cd into that project's directory so that you don't have to manually change it each time.

http://railsapps.github.com/installing-rails.html

Last edited by Brian71 (2012-04-03 14:49:54)

Re: Need Help to "setup" a RESTful webservice

Ok i test and post my result ...

Re: Need Help to "setup" a RESTful webservice

Ok .. i am totally blocked ... I have try to remove everything i have already installed to be sure to make everything in a good way

But now it is worst ! Can someone can help me to clean and "reset" my ruby, rubygems and rails from my server in order make it again from the beginning ?

Thanks.

Last edited by Romain77 (2012-04-03 15:45:25)

Re: Need Help to "setup" a RESTful webservice

Ok i have "purge" all my install of any related with ruby with aptitude purge ruby, aptitude purge rubygems and aptitude purge rails

I have also "implode" RVM in order reinstall it again to be sure ...

I hope everything will works quickly smile I really need this RESTful webservice ASAP to continue my mobile app developpement !

Re: Need Help to "setup" a RESTful webservice

Ok it seems to work ... i have launch my rails server and i can reach it from http://localhost:3000 ...

Now i have to learn and understand how setup a RESTful webservice ... to allow requests on a MySQL DBs

The Tutorial seems to be very good but a little bit 'too much' complete. Could you suggest me to read a part of this tutorial it can explain me what i am looking for ?

Thanks for help

Last edited by Romain77 (2012-04-04 02:01:43)