# Models for external REST services

**URL:** <https://www.ruby-forum.com/t/models-for-external-rest-services/119645>\
**Category:** Rails\
**Created:** [November 8, 2007, 9:25pm UTC](https://www.ruby-forum.com/t/models-for-external-rest-services/119645 "2007-11-08T21:25:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alfredo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e495f1/32.png) [@Alfredo](https://www.ruby-forum.com/u/Alfredo)\
**Post date:** [November 8, 2007, 9:25pm UTC](https://www.ruby-forum.com/t/models-for-external-rest-services/119645/1 "2007-11-08T21:25:03Z")

</div>

Hello, I’m new to rails so as an exercise I’m porting (php to rails)  
a very simple landing page that talks with a third party REST service  
where I just need to do a couple of calls to register a user and show  
the status of the whole process. I felt this would be dead simple to  
do in Rails (I’m still learning) but I’m having a hard time getting it  
working.

My idea was just to have one controller with a couple of actions one  
for each REST call an update my view with RJS. It has been kind of  
frustating since this was so simple to do in php and I honestly  
expected the port to rails to be much simpler, even for someone  
learning the framework.

Thanks for your time, I inlcude the code of what I have so far, any  
help/links are appreciated

This is what my sign\_in partial looks like:

#- view/home/\_sign\_in.rhtml  
\<% remote\_form\_for :sign\_in\_form, :url =\> “home/do\_sign\_in”, :html  
=\> { :id =\> ‘sign\_in\_form’ } do |f| %\>  
  
  
  
  
\<%= f.text\_field :mobile\_field1%\> # by the way, I get an error if  
I try to pass options to the textfield  
\<%= f.text\_field :mobile\_field2%\> # error says the method just  
recieves 2 arguments  
\<%= f.text\_field :mobile\_field3%\>

```
<%= select_tag("sign_selection",options_for_select(@signs) )

```

%\>  
\<%= image\_submit\_tag(“/images/  
subscribe\_now\_btn.gif”, :border=\>0)%\>  
\<%end%\>

# end snippet

#============================

And this is what the model looks like (I assume I need a model for the  
remote\_form\_for) and I’m pretty sure this is far from what I need

# model/sign\_in\_form.rb

class SignInForm \< ActiveRecord::Base

attr\_accessor :mobile\_field1, :mobile\_field2, :mobile\_field3,  
:mobile\_number, :sign

def mobile\_number=(val)  
@mobile\_number = val  
end

# mobile\_number is supposed to be some sort of virtual attribute

def mobile\_number  
@mobile\_field1+@mobile\_field2+@mobile\_field3  
end

def sign=(val)  
@sign = val.capitalize  
end

def sign  
@sign  
end

def mobile\_field1=(val)  
@mobile\_field1 = val  
end

def mobile\_field1  
@mobile\_field1  
end

#getters and setters for the other mobile\_field

# end snippet

#============================  
On the side of the controlloer I have no idea how to start, this is  
what I think it should look like,

def do\_sign\_in

@sign\_in\_form #this should come from the form in the view, I have no  
idea how to get this object

api\_url = “[www.example.com/some\_api.php](http://www.example.com/some_api.php)”

response = some\_object.do\_post (api\_url, :params =\>{ “api\_key” =\>  
@key, “param1” =\> @sign\_in\_form.field1, “param2” =\>  
@sign\_in\_form.field2, } )

# after this we should go to a do\_sign\_in.rjs and do all the ajax

updates

end

#============================
