# REST with 1.2.3

**URL:** <https://www.ruby-forum.com/t/rest-with-1-2-3/153233>\
**Category:** Rails\
**Created:** [November 13, 2008, 6:20pm UTC](https://www.ruby-forum.com/t/rest-with-1-2-3/153233 "2008-11-13T18:20:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5e9695/32.png) [@Bob\_O](https://www.ruby-forum.com/u/Bob_O)\
**Post date:** [November 13, 2008, 6:20pm UTC](https://www.ruby-forum.com/t/rest-with-1-2-3/153233/1 "2008-11-13T18:20:55Z")

</div>

Hello all,

First let me say im a n00b. Im coming into the OOP world from the  
design world. So far so good. With great resources like this, youre  
all making my life less painfull.

Question -

The current project im involved in is in 1.2.3 (not by my choice)

Basically i have a form partial that i want to be able to route the  
information to either create or update, but do this like rails 2 would  
do.

1 form, 1 submit button, and have it be smart enough to know what to  
do.

this is my form code

\<% form\_for :styles, :url =\> styles\_url(:id =\> current\_client.id) do |  
f| %\>  
\<%= render :partial =\> “styles/form”, :locals =\> {:f =\> f} %\>  
\<%= button :action =\> :submit, :label =\> ‘Save Styles’, :class =\>  
‘blue’ %\>

i have a map.resources :styles in my routes

My Styles Controller

def create  
@client = Client.find(params[:id])  
@styles = Styles.new(params[:styles])  
if @styles.save  
flash[:notice] = ‘Your custom styles have been created.’  
redirect\_to :controller =\> “client”, :action =\> ‘edit’, :id =\>  
@client.id  
else  
render :back  
end  
end

def edit  
@styles = Styles.find(params[:id])  
end

def update  
@client = Client.find(params[:id])  
@styles = Styles.find\_by\_client\_id(@client.id)  
if @styles.update\_attributes(params[:styles])  
flash[:notice] = ‘Your custom styles have been updated.’  
redirect\_to :controller =\> “client”, :action =\> ‘edit’, :id =\>  
@client.id  
else  
render :back  
end  
end

any help would be great…

---

<div class="post-metadata">

**Author:** ![Bob\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5e9695/32.png) [@Bob\_O](https://www.ruby-forum.com/u/Bob_O)\
**Post date:** [November 13, 2008, 7:59pm UTC](https://www.ruby-forum.com/t/rest-with-1-2-3/153233/2 "2008-11-13T19:59:32Z")

</div>

On Nov 13, 11:13 am, Bob O [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello all,
> 
> First let me say im a n00b. Im coming into the OOP world from the  
> design world. So far so good. With great resources like this, youre  
> all making my life less painfull.

Welcome!

> Question -
> 
> The current project im involved in is in 1.2.3 (not by my choice)

That’s unfortunate 🙂

> f| %\>  
> I’m rusty on 1.2.3 syntax, but I think you can just specify the method  
> needed:

form\_for :styles, :url =\> styles\_url(:id =\>  
current\_client.id), :method =\> :put do

so actually, you might want to move this into your form partial,  
passing a local variable to indicate whether or not you should  
use :method =\> :put or :method =\> :post (or you can leave it off  
entirely for the :post case).

I can’t tell from your code, but if your partial is using a variable  
like @styles, then actually you could just look at @styles.new\_record?  
to find out if it’s new (i.e. use :post) or old (i.e. use :put).  
That’s actually what the 2.0 code does internally.

Hope this helps?

Jeff

[www.purpleworkshops.com](http://www.purpleworkshops.com)
