SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to pass parameters

    Hi guys,
    just a simple question that seems unanswered on RoR books, I just
    skimmed 4 of them. I've a Contact model and I've a Note model. Now I
    want a link on the page that shows the contact enabling the user to add
    a new note for that contact.
    Now on the contact page I want to place an 'add note'. I want the user
    to write the note on a separate page. How can I pass the ID of the
    contact to the page? Where should I place this ID in the form for the
    note? (a hidden field?, is there an helper for this?) How should I write
    the action to store this note, I mean how can I distinguish the note ID
    from the contact ID?
    At the end I've a great doubt, am I completely wrong and should I change
    the way to develop in RoR? This last question is even more important so
    if the right way to do what I'm asking is different please tell me.

    Thank you.

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can pass additional parameters to link_to:

    Code:
    link_to "add note", :controller => "notes", :action => "new", :contact_id => @contact.id
    You can extract it from the params hash like this:

    Code:
    params[:contact_id]
    Then you put it in a hidden_field for the "create" action. The name of the note id in the notes-controller is simply "id". The name of the contact is "contact_id".

  3. #3
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Fenrir2, now it works.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •