form_for submit to a custom action

hi forum,

I am new to rails, and i am just getting my hang of things.

how do you pass content captured in a form to a custom method?

I have the following form:

  <% form_for :message, @message, :url => { :action => 'reply'} do |f|
  <table cellpadding="4" cellspacing="5">
         <td>Content:<%= f.text_area :body %></td>
        <td><%= submit_tag "Send" %></td>
  <% end %>

this form is posting to a method called reply(), reply will need to take

the :body from the message, so the incoming request parameters look like

{"message"=>{"body"=>"this is the reply"},

how do i retrieve "body"=>"this is the reply" from the request in the
reply action?

any tips are appreciated!


You can use a book on Rails like the one from Pragmatic Programmers.
There are many nice features in the framework that need explanation
and you are missing out on what Rails has to offer by hack and slash
which constraints your thinking to the other frameworks you are used

To answer your question, assuming the form is for the object of type
Message, you can do a[:message]) in your
controller and access the attribute normally.

In general, the params hash (method 'params') is always available to
your controller actions. You literally wrote how your params hash
looks like (your incoming request parameters), so it's just plain Ruby
code to retrieve the contents of the hash:
params[:message] returns the hash {'body' => 'this is the reply'}
so params[:message]['body'] would give you the string 'this is the

Beside checking a Rails book, I found that most useful is a good grasp
of Ruby itself (the 'pickaxe' book is a good start). You can learn
Rails pretty much on the go, but good Ruby skills are really valuable
to move on quickly.