`
CaiDeHen
  • 浏览: 89549 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

#63 Model Name in URL

阅读更多
By default, Rails uses the model's id in the URL. What if you want to use the name of the model instead? You can change this behavior by overriding the to_param method in the model. Watch this episode for details.
# product.rb
def to_param
  "#{id}-#{permalink}"
end

# controller
@product = Product.find(params[:id])
or

# product.rb
def to_param
  permalink
end

# controller
@product = Product.find_by_permalink(params[:id])
分享到:
评论

相关推荐

    Android代码-利用注解自动生成Gson‘s Model的库

    2.Just write a jsonModel name 3.Build the project (->Make Project) Then you can use UserInfo to do something~ GIF Demo Picture is big,wait a minute... Usage 1.Add apt in project's build.gradle ...

    asp.net mvc

    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/> Create a new ASP.NET MVC 2 application. Copy the files from the Scripts directory of the new application into the...

    scala的orm框架srom.zip

    // Declare a model: case class Artist( name : String, genres : Set[Genre] ) case class Genre( name : String ) // Initialize SORM, automatically generating schema: import sorm._ object Db extends ...

    freemarker总结

    sort_by(name) 表示所有的user按user.name进行排序 hashes内置方法 hash?keys 返回hash里的所有keys, 返回结果类型sequence hash?values 返回hash里的所有value, 返回结果类型sequence 模板 使用FTL(freeMarker...

    javaee三大框架整合宅急送项目lib包

    <result name="findInStoreTaskSUCCESS">/WEB-INF/pages/zhongzhuan/instore_list.jsp <result name="findOutStoreTaskSUCCESS">/WEB-INF/pages/zhongzhuan/outstore_list.jsp <result name=...

    ORM软件monalisa-orm.zip

    for(User x:User.WHERE().name.like("zzg%").status.in(0, 1).SELECT().select()){ System.out.println(x); } //SQL: SELECT * FROM `user` WHERE (`name` like 'zzg%' AND `status` >= 0)  // OR (`name` = '...

    OSGI in Action

    Applications specification 488 ■ Standard WARs: the Web URL Handler 492 15.2 Providing and consuming web services 493 Providing a web service 494 ■ Consuming a web service 499 Distributing services ...

    使用Huggingface、PEFT和LoRA训练大型语言模型(LLM)的demo代码

    你可以通过查看该脚本的头部来调整一些设置,如模型名称(model_name)、是否以8位加载模型(load_in_8bit)、LoRA文件路径(lora_file_path)、文本文件名(text_filename)、输出目录(output_dir)、截断长度...

    trinitygo:适用于grpc,http,IOC,DI,spring,unittest的golang框架

    $ trinitygo NewCrud [Your Model Name] $ swag init // start your journey in Trinity // you can check the demo under example folder 概述 声明性路由器 IOC容器和依赖注入 定制中间件 定制运行时(跟踪分析,...

    mask rcnn.rar

    免费分享互帮互助 ...The model generates bounding boxes and segmentation masks for each instance of an object in the image. It's based on Feature Pyramid Network (FPN) and a ResNet101 backbone.""",

    Learning Joomla! 1.5 Extension Development Creating Modules, Components, and Plugins with PHP

    Some of the code is also separated out into a helper class so that the main code generating the module stays simple. Chapter 6 rewrites the component developed in Chapters 2, 3, and 4 so that ...

    springmybatis

    <property name="url" value="jdbc:mysql://127.0.0.1:3306/mybatis" /> <property name="username" value="root"/> <property name="password" value="password"/> ...

    loopback-slug:url友好的loopback.io框架生成器

    url友好的loopback.io框架生成器。 安装 该模块通过npm安装: $ npm install loopback-slug or $ npm install git://github.com/rikhart/loopback-slug.git 用法示例 编辑/common/models/name_of_your_models.js并...

    Jquery 1.3 简体中文手册

    $.inArray(value, array) $.merge(first, second) $.unique(array) 测试操作 $.isArray(obj) $.isFunction(obj) 字符串操作 $.trim(str) URL $.param(obj) 关于 关于jQuery 1.3 版翻译 关于jQuery 1.2 版...

    JQuery 1.3 中文参考手册

    $.inArray(value, array) $.merge(first, second) $.unique(array) 测试操作 $.isArray(obj) $.isFunction(obj) 字符串操作 $.trim(str) URL $.param(obj) 关于 关于jQuery 1.3 版翻译 关于jQuery 1.2 版...

    jQuery1.4 API

    [queueName]) 设置 jQuery.fx.off Ajax Ajax 请求 $.ajax([options]) load(url, [data], [callback]) $.get(url, [data], [fn], [type]) $.getJSON(url, [data], [fn]) $.getScript(url, [callback]) $.post(url, ...

    CodematicDemoMVC

    @foreach(var item in items){ <span>@item.Prop } @if(foo) { @Dsad } Hello @Title . @name 输出@符号 @@forr dsa ds 输出无空格或标记位置 <span> ISBN@(isbnBumber) 注释 @* dsad *@ @{ ...

Global site tag (gtag.js) - Google Analytics