Liquid error: undefined method `source' for nil:NilClass Liquid error: undefined method `url' for nil:NilClass

Is this your first visit? You may want to subscribe to the feed.

Articles tagged with edge

Fixed in edge rails: table name quoting

One of more annoying ActiveRecord bugs has finally been fixed in edge rails after 2 years. Table names in SQL queries are now properly escaped.

On nearly every project it seems I end up having a table name that doesn’t work in either MySQL or sqlite. While they usually are SQL reserved words, most databases allow you to use reserved words if they’re properly quoted.

The following, which doesn’t work in MySQL:
DELETE FROM values;

will now be:

DELETE FROM `values`;
Code: edge Oct 16, 2007 ● updated Oct 16, 2007 2 comments

Edge Rails gets layouts for partials

Edge Rails picked up a new feature today we’ve often longed for at Collective Idea. Partials can have a layout:

<%= render :partial => "user", :layout => "admin", :collection => @users %>

This would wrap the user partial with the admin layout, which in this example adds an edit link for the admin user:

<% content_tag_for :li, user do %>
    <%= yield %> 
    <%= link_to 'Edit', edit_user_path(user) %>
<% end %>

Another cool feature in this patch is the ability to add a layout to any block in a template, for those one-off situations, or to just tidy up repeated markup:

<% render :layout => "admin", :locals => { :user => owner } do %> 
    <%= render :partial => "user", :collection => @users %>
      (owner)
<% end %>
Code: edge Aug 02, 2007 ● updated Aug 06, 2007 0 comments

Using a singleton resource for an admin section

Applications with an admin section often have a URL like http://myapp.com/admin, with that URL being a summary page, and all the other admin pages be under that URL (like, http://myapp.com/admin/users to edit users.). Without defining a lot of routes, this hasn’t been very easy with Rails…until now. Singleton resources have been merged into the 1.2 branch from edge-rails, so I thought I would share a little pattern that I’ve been using in several of my apps to accomplish this.

Singleton resources are like regular resources in Rails 1.2, except that they don’t have an :id parameter. This happens to work perfectly for using one controller to show a summary page, and then nesting the routes for other controllers inside of it.

The routes definition looks like this:

map.resource :admin do |admin|
  admin.resources :users
end

Update: The key here is map.resource (singular).

To make this work, generate an admin controller:

script/generate controller admin

You can now set up the “show” action in the admin controller to display a summary page.

The named route users_path now generates the URL /admin/users.

Code: edge Feb 04, 2007 ● updated Feb 05, 2007 13 comments

Subscribe

Browse by Tag