SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2004
    Location
    Directly above the center of the Earth
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date Select How the funk do the data out?!

    Hi,

    Just a really stupid point, that bugged me for hours last night.

    I have a form which has 2 date_select's in, and one normal select.

    The select looks something like this:
    Code:
    <%=date_select(:propertySearch, :start_date, :order=>[:day,:month,:year])%>
    <%=select(:propertySearch, :people, %w{ 1 2 3 4 5 6 7 8 9 10 })%>
    in my controller at property search (where the form goes) i can get people out:
    Code:
    propertyResults=params[:propertySearch]
    people = propertyResults[:people]
    However
    startDate= propertyResults[:start_date] doesnt return me anything.

    Havent quite grasped the whole form posting thing yet.. GIMME MY VARIABLES BACK!

    Anyone know how i can do this?

    Thanks

  2. #2
    SitePoint Enthusiast kyko's Avatar
    Join Date
    May 2006
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you make a rails date_select box you are actually making three html select boxes, all of which must have unique name attributes. the way rails normaly makes form field name attributes is name="object[fieldname]" or in your case name="propertySearch[people]". But since you are only providing one field name for three date selects rails makes it like name="propertySearch[date(xi)]" where x is the the select field number.
    So if you need the month, you can do startDateMonth = propertyResults['start_date(2i)']
    likewise for the day and year of course. However this is kind of annoying and will only return the month number not the month name. To change it into the month name you have compile your date params into a Date object and then use the strftime method.
    I've never done this myself but here is a little snippet that should help you out.
    http://www.bigbold.com/snippets/posts/show/2476
    Stop Global &nbsp;


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
  •