This episode will show you how to make a model which isn't based on Active Record. You may want to do this if a resource isn't backed by the database.
# models/letter.rb
class Letter
attr_reader :char
def self.all
('A'..'Z').map { |c| new(c) }
end
def self.find(param)
all.detect { |l| l.to_param == param } || raise(ActiveRecord::RecordNotFound)
end
def initialize(char)
@char = char
end
def to_param
@char.downcase
end
def products
Product.find(:all, :conditions => ["name LIKE ?", @char + '%'], :order => "name")
end
end
# letters_controller.rb
def index
@letters = Letter.all
end
def show
@letter = Letter.find(params[:id])
end
<!-- letters/index.html.erb -->
<% title "Select a Letter" %>
<% for letter in @letters %>
<%= link_to letter.char, letter %>
<% end %>
<!-- letters/show.html.erb -->
<% title "Products for Letter #{@letter.char}" %>
<p><%= link_to "Select a Letter", letters_path %></p>
<%= render :partial => @letter.products %>
分享到:
相关推荐
### 3D Constrained Local Model (CLM-Z) for Rigid and Non-Rigid Facial Tracking #### 概述 本文介绍了一种新的3D约束局部模型(CLM-Z),该方法在变化的姿态下能够进行鲁棒性的面部特征追踪。研究通过整合深度...
### Color Active Shape Models (CASM): An Enhanced Approach for Tracking Non-Rigid Objects in Color Videos #### Introduction In the field of computer vision and image processing, tracking non-rigid ...
本文档《一种用于自动技术插图的非真实感照明模型》(A Non-Photorealistic Lighting Model For Automatic Technical Illustration)是关于非真实渲染(即卡通渲染)的重要文献之一。该文发表于1999年,作者包括Amy ...
《正矩阵因子分解——一种非负因子模型》 正矩阵因子分解(Positive Matrix Factorization,PMF)是一种在数据处理和分析中广泛应用的非负因子模型。该模型尤其适用于那些包含误差估计的数据值,以及对非负性有严格...
非顺序光线追踪(Non-Sequential Ray Tracing)是光学设计软件ZEMAX中的一项高级功能,与传统的顺序光线追踪相比,它提供了更为复杂且灵活的光线处理方式。在顺序光线追踪模式下,光线必须按照预定义的顺序通过一...
These properties make them particularly suitable for modeling financial data, which often exhibit extreme values and non-normal distributions. By incorporating α-stable innovations into the GARCH ...
空中操纵的全身扭矩水平非线性模型预测控制(Full-Body Torque-Level Non-linear Model Predictive Control,简称nMPC)是一种针对复杂机器人,如人形机器人、四足机器人或无人驾驶空中操纵器(Unmanned Aerial ...
《基于非局部微分算子的统一Retinex模型》 在图像处理领域,Retinex理论是一种模拟人类视觉系统对图像亮度和对比度感知的算法。它试图解释为何我们能在光照条件变化很大的环境中,仍然能识别出物体的颜色和形状。...
来自开发者:“Active Ports 是一个在Windows NT/2000/XP 下易于操作的工具,它能够让你监控本机上所有打开的TCP/IP以及UDP端口,Active Ports 可以让你了解哪个程序在哪个端口应用。”
#ifdef NON_ENGLISH_PATH_FILENAME_SUPPORT size_t filenameLength = wcslen(filename) * 2; #else size_t filenameLength = wcslen(filename); #endif 在.h文件中添加:#define NON_ENGLISH_PATH_FILENAME_...
### 无限项与非理性模型 #### Lambda演算相关问题及无限Lambda项的语法与语义 在探讨无限Lambda项之前,我们先简要回顾一下Lambda演算的基础知识及其在计算机科学中的应用背景。 **Lambda演算**是一种形式化的...
Active@ Partition Recovery for Windows - will help you if non-system partition is lost, i.e. you can boot Windows, install and run the software from under Windows to recover deleted or damaged ...
# Needed only on Android 9 (P) and 10 (Q) on non-Pixel phones. adb shell setprop persist.traced.enable 1 On Linux and Mac: curl -O ...
# Train non-contextualized model python bin/train_hate_classifier.py --output_path models/bert-non-contextualized-hate-speech-es/ --epochs 10 python bin/train_category_classifier.py --output_path ...
the image, an improved active contour model based on level set method is proposed. Defining a novel SPF function with a nonnegative kernel function and local intensity clustering property
ActiveRecordFlorder Trello的订购算法极大地启发了富客户端应用程序的浮点ActiveRecord...gem 'active_record_florder' , '~> 0.1.0' 或只是通过Ruby Gems安装 gem install active_record_florder 阿皮 这个gem为Act
### Android Studio 中非零退出值 (Non-Zero Exit Value) 错误详解及解决方法 #### 背景概述 在使用 Android Studio 进行应用开发的过程中,有时会遇到 `finished with non-zero exit value` 的错误提示。这类错误...