Question About Forms

Hey everybody,
I'm new on RoR and I was wondering with sb could help me.
I have one page that interacts with a lot of controllers and actions,
so I need to create many forms(one per action).
Example: In this page I send message to user, make one vote in one
post, remove one post. So I create one action per each action.
My quesion is: There is any other way to do that?
I think that many forms inside one page make the code ugly, but I
don't know if I'm correct.
Thanks :smiley:

Example: In this page I
1) send message to user,
2) make one vote in one post,
3) remove one post.

I'm not 100% sure what you mean by #1 but I'll assume that it requires a
text area and a submit button. I'd probably use a regular form for this
although scriptaculous offers many "Web 2.0" ways to do this as well
(http://script.aculo.us/)

#2 can be done with an AJAX request. I'd have a button and use the
"onClick" event of the button to send the AJAX request to a method that
is looking for a "post". e.g. in your routes file, define the action's
method as :post. There should be samples in various Rails documents and
also perhaps on the prototypejs.org site (since you are likely using
prototype.js as your javascript library).

#3 appears to me as the normal delete. Go to the typical
"index.html.erb" page for a sample of how to do a delete in Rails. It
appears to the user as just a link and sends a "delete" http message
(although its not really a delete http message as I recall). #3 in
particular indicates that you need to learn about "Restful" routes in
Rails. Its really wonderful. There are tons of info about Restful
routes on the web.

The Rails book(s) from Pragmatic Programmers is very good and would help
here.

Good luck!
pedz

Hi Perry,
Thanks for help me, I will try to follow your tips ;D
May I ask you another question?
If yes, my question is:
Is a good practice in this page has only one BIGGGGG form that treat
all the actions and this action has a lot of (if
params[:button_name]), or has many forms responsible to treat each
action?

Thanks ;D

This is more of a design question. There is nothing wrong with many
forms. And usually keeping things separate leads to more stable, easier
to maintain code. So I would probably opt for many small forms rather
than one big one.

HTH
pedz