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
reply'
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.
On Sep 9, 12:04 pm, Mukund <[EMAIL PROTECTED]> wrote:
> 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.
>
> To answer your question, assuming the form is for the object of type
> Message, you can do a xyz=Message.new(params[:message]) in your
> controller and access the attribute normally.
>
> On Sep 9, 2:59 pm, Paul Li <[EMAIL PROTECTED]> wrote:
>
> > hi forum,
>
> > I am new to rails, and i am just getting my hang of things.
>
> > Problem,
> > 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">
> > <tr>
> > <td>Content:<%= f.text_area :body %></td>
> > <tr>
> > <td><%= submit_tag "Send" %></td>
> > </tr>
> > </table>
> > <% 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
> > this:
>
> > {"message"=>{"body"=>"this is the reply"},
> > "commit"=>"Send",
> > "authenticity_token"=>"e2a058071a4037d85008f46b35818e160f5230ce"}
>
> > how do i retrieve "body"=>"this is the reply" from the request in the
> > reply action?
>
> > any tips are appreciated!
>
> > ~zonman
> > --
> > Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---