1.如何统计一个分类中的文章数?是通过在Category表中设置一个topics_count字段,每次增加或删除时都更新该字段,还是直接在view层中通过Topic.count [ "category_id = ?", category.id ]语句直接做统计?后一种办法会不会降低速度?
2.统计文章浏览次数的字段view_counts是不是应该在show的时候每次加1?但是这样的话每次回复评论的时候都会加1,这样好不好?
3.网页跳转锚点如何设置?除了<a name="new_comment" ></a>外是不是有什么辅助方法?
4.要找一篇文章的前一篇和后一篇的话怎么找(按发表时间的顺序)?我用的办法好像不怎么好。
5.是不是为了过滤一条信息,在view层和controller层都要写过滤代码?比如一篇文章有“删除”的选项,但不希望未登录的人执行此操作,那是不是应该在view层写上 <% if login? %> 之类的代码,然后在controller层也过滤一下未登录用户?有没有什么更好的办法?
6.如何控制表单中下拉菜单的CSS?比如改变下拉箭头样式的CSS代码怎么写?
7.如何对多条记录进行更新。比如我“参数设置”(controller/admin/config_controller.rb和view/admin/config/index.rhtml中的代码我总觉得写的不怎么舒服)
8.比如说我有2个前置过滤,一个是“是否第一次登录”,另一个是“是否是管理员”,有2个redirect_to,就会出现下面的错误怎么办?
[quote]Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and only once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return". Finally, note that to cause a before filter to halt execution of the rest of the filter chain, the filter must return false, explicitly, so "render(...) and return false".[/quote]
9.改变默认的错误信息以后,比如在environment.rb文件中定义too_short错误的错误信息为“长度太短”,那如果注册输入login_name太短的话就会提示“login name长度太短”,这样就暴露了字段名,如何能替换掉其中的"login name"。还有如何修改错误提示框中“2 errors prohibited this comment from being saved”“There were problems with the following fields:”这些信息,我希望都改成中文。
默认的错误信息:
10.为什么有时候不能显示错误信息,如/message/index发表空留言就不会有错误信息,我只能改成在controller中控制。
11.如何只更新一条记录的部分字段?是通过@category = Category.find(params[:id], :select => "title, description")这种语句吗?但我每次用这个都会更新出错。
12./view/shared/item/_archives.rhtml里的代码写的很糟糕,感觉放了太多逻辑了,有什么办法把逻辑提出来,还有存档的代码怎么写比较好?
2.统计文章浏览次数的字段view_counts是不是应该在show的时候每次加1?但是这样的话每次回复评论的时候都会加1,这样好不好?
3.网页跳转锚点如何设置?除了<a name="new_comment" ></a>外是不是有什么辅助方法?
4.要找一篇文章的前一篇和后一篇的话怎么找(按发表时间的顺序)?我用的办法好像不怎么好。
@pre_topic = Topic.find(:first, :conditions => [ "created_at < ?", @topic.created_at ], :order => "created_at DESC")
@next_topic = Topic.find(:first, :conditions => [ "created_at > ?", @topic.created_at ])
5.是不是为了过滤一条信息,在view层和controller层都要写过滤代码?比如一篇文章有“删除”的选项,但不希望未登录的人执行此操作,那是不是应该在view层写上 <% if login? %> 之类的代码,然后在controller层也过滤一下未登录用户?有没有什么更好的办法?
6.如何控制表单中下拉菜单的CSS?比如改变下拉箭头样式的CSS代码怎么写?
7.如何对多条记录进行更新。比如我“参数设置”(controller/admin/config_controller.rb和view/admin/config/index.rhtml中的代码我总觉得写的不怎么舒服)
8.比如说我有2个前置过滤,一个是“是否第一次登录”,另一个是“是否是管理员”,有2个redirect_to,就会出现下面的错误怎么办?
[quote]Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and only once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return". Finally, note that to cause a before filter to halt execution of the rest of the filter chain, the filter must return false, explicitly, so "render(...) and return false".[/quote]
9.改变默认的错误信息以后,比如在environment.rb文件中定义too_short错误的错误信息为“长度太短”,那如果注册输入login_name太短的话就会提示“login name长度太短”,这样就暴露了字段名,如何能替换掉其中的"login name"。还有如何修改错误提示框中“2 errors prohibited this comment from being saved”“There were problems with the following fields:”这些信息,我希望都改成中文。
默认的错误信息:
# :inclusion => "is not included in the list",
# :exclusion => "is reserved",
# :invalid => "is invalid",
# :confirmation => "doesn't match confirmation",
# :accepted => "must be accepted",
# :empty => "can't be empty",
# :blank => "can't be blank",
# :too_long => "is too long (maximum is %d characters)",
# :too_short => "is too short (minimum is %d characters)",
# :wrong_length => "is the wrong length (should be %d characters)",
# :taken => "has already been taken",
# :not_a_number => "is not a number"
10.为什么有时候不能显示错误信息,如/message/index发表空留言就不会有错误信息,我只能改成在controller中控制。
11.如何只更新一条记录的部分字段?是通过@category = Category.find(params[:id], :select => "title, description")这种语句吗?但我每次用这个都会更新出错。
12./view/shared/item/_archives.rhtml里的代码写的很糟糕,感觉放了太多逻辑了,有什么办法把逻辑提出来,还有存档的代码怎么写比较好?