开发者

How Can I Load localhost:3000 in Chrome On Issuing A "rails s" Command?

My workflow looks like this:

  1. $>mate .
  2. Edit stuff using textmate
  3. Go to command line to run $>rails s
  4. Go to Chrome to click a bookmark that loads localhost:3000
  5. View the app
  6. Load text mate to fix/revise
  7. Back to command line to git
  8. Repeat

Is it possible to rig step 3 so that it will also load a new tab with localhost:3000 in it? One less click, sa开发者_StackOverflowved many times.


Since you're using TextMate I'll assume you're on a Mac.

Two things you can do.

  1. Setup Phusion Passenger on Apache (Mac OS X already has apache) so you save yourself the rails s. You can find tutorials on this at many location. But basically you follow the instructions from the Passenger website and then install the Passenger PreferencePane to make your life easier. To do this you'll need the XCode installed.

  2. Start the rails server in the background then calling open to open the URL

    #!/bin/bash  
    #  
    # save this in script/start.sh  
    # don't forget to do chmod +x script/start.sh  
    rails s &  
    sleep 4
    open http://localhost:3000  
    


In addition to the recommendation for Passenger above, I'd also add that you can install the "Passenger Pref Pane" that will let you easily add projects and set their environments (production/development).

Passenger + Passenger Pref Pane will completely eliminate the need for rails -s, with minimal fussing on the Apache config files.

I think Textmate also allows you to do some scripting that might even get you to be able to launch and open the url in Chrome on save, but I haven't ventured into that area of Textmate yet, and it would probably take more work than just hitting refresh after the save.


If you don't mind adding some code, you could put this in your config/application.rb:

config.after_initialize do
  if Rails.env == 'development'
    system('open /Applications/Google\ Chrome.app http://localhost:3000') 
  end
end

That will open a new tab each time though and if this is a multi-person project, you may get complaints.

Another option would be to look at live-reload to get the tab to refresh when a file changes. Even without Passenger, on Rails 3 I rarely have to restart the server, so just reloading the tab might make more sense.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜