Posts [ 9 ]

Topic: Need Help to "setup" a RESTful webservice

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.

Re: Need Help to "setup" a RESTful webservice

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"

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.