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 %>
分享到:
相关推荐
Non sequential model in zemax
Positive matrix factorization_ A non-negative factor model with optimal utilization of error estimates of data values †.pdf 正矩阵因子分解_最佳利用数据值误差估计的非负因子模型†.pdf
空中操纵的全身扭矩水平非线性模型预测控制_Full-Body Torque-Level Non-linear Model Predictive Control for Aerial Manipulation.pdf
3D Constrained Local Model for Rigid and Non-Rigid Facial Tracking
微分方法求解Retinex算法,A unifying retinex model based on non-local differential operators
非常好的关于非真实渲染(卡通渲染)的文档。
Non-negative Latent Factor Model based on β-divergence for Recommender Systems
来自开发者:“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 calculus related problems and about syntax and semantics of infinite lambda terms
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 ...
基于低维算子机器学习逼近的非侵入式非线性模型降阶_Non-intrusive Nonlinear Model Reduction via Machine Learning Approximations to Low-dimensional Operators.pdf
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
active suspension system non-linear analysis
ActiveRecordFlorder Trello的订购算法极大地启发了富客户端应用程序的浮点ActiveRecord...gem 'active_record_florder' , '~> 0.1.0' 或只是通过Ruby Gems安装 gem install active_record_florder 阿皮 这个gem为Act
Algorithms for Non-negative Matrix论文描述希望帮助到大家
非血红素铁化合物模拟脂氧合酶活性,梅伏生,欧春平,使用一个N6六齿配体ctb,我们合成了三个铁配合物FeII(ctb)](ClO4)2.EtOH (1), [FeIII(OEt)(Hctb)](ClO4)3.EtOH (2), and [FeIII(OMe)(Hctb)](ClO4)3.3MeOH.4.5...
non local means paper