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…