7 Jul 2011, 11:43pm
Posts:
by

leave a comment

Changing GitHub Issue State in Git Commit Message

Changing issue state in git commit message for Github issues

fixes #xxx
fixed #xxx
fix #xxx
closes #xxx
close #xxx
closed #xxx

Example

git commit -am'complete bug fix closes #123'

Collection Select Helper and OnChange Event in Rails

Given a collection of Active Record objects, you may use the collection_select helper method to produce a select form field. You need to pass in a number of arguments to the helper function.

1) object – your model object used in the collection
2) method – a valid model attribute or method
3) collection – a collection of active record model objects
4) option_value – value being set from the model for the <option value=”option_value”> html element
5) option_name – what is displayed for the user e.g., <option> option_name <
6) option – general options
7) options for the select html element

# helper and arguments...
# collection_select( model, id, collection, option_value, option_name, options, html_options)

&lt;%= collection_select("states", "state_id",
  State.participating,
  "abbreviation", "name",
   {:selected=&gt; get_current_state_or_nil },
   {:onchange=&gt;"document.location='/states/'+this.value"}
) %&gt;

#which will produce something like...

<pre id="line27">&lt;select id="state_id" name="state[id]" onchange="document.location='/states/'+this.value"&gt;
&lt;option value="AL"&gt;Alabama&lt;/option&gt;
&lt;option value="AK"&gt;Alaska&lt;/option&gt;
&lt;option value="AZ"&gt;Arizona&lt;/option&gt;
&lt;option value="AR"&gt;Arkansas&lt;/option&gt;
&lt;/select&gt;

Rounded Corners with CSS

.rounded_corners {
     -moz-border-radius: 20px;
    -webkit-border-radius: 20px;
    -khtml-border-radius: 20px;
    border-radius: 20px;
}

A List of Every High School in the United States in Pipe Delimitted Form (2005)

Here is a text file containing every high school in the United States(2005), including city, state, zip code and high school name.

us_high_schools_pd

The Context of Markup vs Expressions of Equality in Determining the Meaning of Angled Brackets

In the WordPress editor (html mode) you’ll need to become friends with < and > if you plan on showing any code (php, html… xml, most languages actually) that readers will want to understand.

I never thought about it, but assumed that the lt and gt stood for left, and gt, well, i couldn’t quite place it, respectively. But alas, it dawned on me. Lt = less than while gt = greater than. Seems obvious now, but when you are thinking about angled brackets as markup, rather than as logic in an expression, the meaning that has value happens to be left vs. right.

Context is important.

Scope Routes/URLs By Username (like Twitter) in Your Rails Application

There are a few things that need to be taken care of before you can get this to work. The first thing (although, any of the following steps can be done in any order) to take care of involves your User model. You need to override the to_param method, so that Rails will appropriately use the username attribute rather than user_id when constructing paths.

#in app/models/user.rb
def to_param
  "#{self.username}"
end

Next we move onto routing our resources. Here it gets a little tricky because Rails is building paths for us. Remeber, you can get a list of all currently defined routes in your application by running the routes rake task

rake routes

We need to set the path_prefix option on any of our resources we want scoped by the username. For instance, in this example, I have set up a Status model and statuses_controller, whose urls shall be scoped by the username. You can apply the path_prefix to any number of other resources in your routes config file. They symbol used is arbitrary, but will be made available in the params hash, in this case params[:user_id]. You also need to exclude the show action on your users resources declaration. The reason is that, otherwise, Rails will include the controller name in the path like /users/username, which doesn’t look as clean as just /username. You then need to redefine this route explicitly (last line in the routes config shown here).

#in app/config/routes.rb
map.resources :statuses,   :path_prefix =&gt; '/:user_id'
map.resources :users,     :except =&gt; [:show]
map.user '/:username' :controller =&gt; 'users', :action =&gt; 'show'

Finally, you get to call these routes in your views or use them in your controllers. You use the same link_to, url_for methods to generate paths. When constructing the resources you have setup with the path_prefix declartion, remember you need the user model as the first argument, followed by said resource.

&lt;%= link_to(status.title, status_path(status.user,status) %&gt;
# or in a controller
redirect_to status_path( status.user, status )

That’s pretty much it. If anyone has another way of doing this let me know!

How Beautiful is Ruby?

Working with Ruby and in particular Rails, it’s easy to take the beauty inherent in the language for granted. I mean look at this code. If you read it aloud to yourself, it reads like an english sentence that any non programmer can understand.

Forum.categories.map do |category|
  link_to category.name, category
end.to_sentence

Forum categories map do category, link to category name, the category, end and convert to a sentence. The code returns a an english sentence as well.

Fish, French Bread, Coffee and Hamburgers with each linked to the correct resource as well!

Deploying to Dreamhost

Remember to include the host declaration in the database.yml file when you deploy to Dreamhost. Dreamhost does not use “localhost” which is typically the default setting when using the mysql adapter and developing locally or even on a small site.

At least for me, when I ported a Rails app to Dreamhost, this was the only “Gotcha”, because my log files were not reporting any errors and were instead serving the 500 something went wrong file.
A sample config/database.yml file

production:
  adapter: mysql
  username: youruser
  password: yourpasswd
  database: ror_production_db
  host: mysql.yourdomain.com

To port, I unpack my gems, if I haven’t already

rake gems:unpack

Then I freeze and package rails w/ my app just in case versions aren’t exact

rake rails:freeze:gems

Then I upload to Dreamhost!

8 Aug 2010, 10:38pm
Posts:
by

leave a comment

oh russian text, i thought you had something valuable to share…

but no, you were only clever enough to use your native tongue in an attempt to fool me into publishing your funny, spam comment! thanks to google.com/translate, you were foiled in your plot to usurp traffic from my site