Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
3 total  XML / RSS feed 

default layout for a controller

// description of your code here
In your controller add the name of the .rhtml file in /apps/layouts/ that you want to use, without the suffix (.rhtml).
When rails spits out your view, it will use this given layout as the container for your rendered action.
layout ""

Gmap Module patch

// How to use Views to display Gmap of nodes of node-type?
// http://drupal.org/node/73420
// http://drupal.org/files/issues/gmap_view.patch

--- gmap.module  2006-07-15 12:23:18.000000000 -0700
+++ gmap.module.new   2006-07-15 12:22:42.000000000 -0700
@@ -1191,20 +1191,21 @@
  */
 function theme_views_view_gmap($view, $nodes) {
   $fields = _views_get_fields();
+       $markers = array();
   foreach ($nodes as $node) {
     $node_data = node_load(array("nid"=>$node->nid));
     $location = $node_data->location;
-    if (strlen($location['lat'])>0 && strlen($location['lon']>0)) {
-      $newmarker['label'] = '';
+    if (($location['lat']) && ($location['lon'])) {
+                       $marker_label = "";
       foreach ($view->field as $field) {
-        $newmarker['label'] .= "

" . views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node) . "</p>"; + $marker_label .= "<p>" . views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node) . "p>"; } - $newmarker['point']= $location['lat'] . ',' . $location['lon']; - $newmarker['markername']='drupal_view'; - $thismap['markers'][]= $newmarker; + $markers[] = array('markername'=>'view', + 'label' => $marker_label, + 'point' =>$location['lat'] . ',' . $location['lon']); } } + $thismap = array('id' => 'view_gmap', 'markers' => $markers); $output .= gmap_draw_map($thismap); return $output; } -

ActiveRecord DOM IDs

The solution—or at least a nice, cheap bandaid that can be applied easily, consists of adding a method to ActiveRecord::Base to help generate these ids without any brainpower involved.

Here’s a very simple implementation that I use in my projects, courtesy of Jamis Buck:



class ActiveRecord::Base
  def dom_id(prefix=nil)
    display_id = new_record? ? "new" : id
    prefix ||= self.class.name.underscore
    prefix != :bare ? "#{prefix.to_s.dasherize}-#{display_id}" : display_id
  end
endSo, you can do stuff like this in your views:

<ul>
<% @entries.each do |entry| %>
  
  • > <%= entry.body %>
  • <% end %> And stuff like this in your controller: def remove_entry entry = JournalEntry.find(params[:id]) update_page do |page| page[entry.dom_id].remove end end
    « Newer Snippets
    Older Snippets »
    3 total  XML / RSS feed