SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A few basic questions

    1. How do you use the link_to method to call an action and pass it parameters so the url looks like

    http://www.example.com/month_view/2008/01

    I know how to make it look like

    http://www.example.com/month_view/?year=2008&month=01

    when I do this <%=link_to "next", :action=> "month_view/2008/02" %>
    it just escapes the forward slashes so the url looks like

    http://www.example.com/month_view%2F2008%2F02

    2. Is it possible to develop a ROR app without have a db to connect to ... If I try to run a rails app and haven't created a mysql db, it gives me an error message and will not load the app.

  2. #2
    SitePoint Addict ruby-lang's Avatar
    Join Date
    Aug 2007
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Add a route to your routes.rb to do that. It will look like this:
    Code:
    map.connect "monthly_view/:year/:month",
                :controller => 'application',
                :action => 'monthly_view'
    Just tweak it to the actual controller and action you are using, and remember to add this before the default routes, because they are evaluated in the order they appear in the file.

    EDIT: Oh yes, and then you can create the link simply using :year and :month as named parameters:

    Code:
    <&#37;= link_to "next", :action=> "month_view", :year => "2008", :month => "02" %>

  3. #3
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ruby-lang View Post
    EDIT: Oh yes, and then you can create the link simply using :year and :month as named parameters:

    Code:
    <%= link_to "next", :action=> "month_view", :year => "2008", :month => "02" %>
    See ... I tried that and the url becomes something like
    http://www.example.com/month_view/?year=2008&month=02

    I want it to be
    http://www.example.com/month_view/2008/02

  4. #4
    SitePoint Addict ruby-lang's Avatar
    Join Date
    Aug 2007
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is your routes.rb like after you added that route? What version of rails are you using?

  5. #5
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a million ruby-lang ... changing the routes worked perfectly!

  6. #6
    SitePoint Enthusiast AllTom's Avatar
    Join Date
    Feb 2008
    Location
    Wherever danger lies...
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ikeo View Post
    2. Is it possible to develop a ROR app without have a db to connect to ... If I try to run a rails app and haven't created a mysql db, it gives me an error message and will not load the app.
    The wiki is down right now, but when it is up you can see how to use Rails without ActiveRecord attempting to establish a database connection:

    http://wiki.rubyonrails.org/rails/sh...thoutADatabase

    It comes down to adding/uncommenting this line in your config/environment.rb file:

    config.frameworks -= [ :active_record ]

    This will prevent ActiveRecord from being loaded at all.

  7. #7
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay ... I'm going to try this.


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
  •