原文參考:[url]http://rails-bestpractices.com/posts/26-move-code-into-helper[/url]
壞習慣:
看了就覺得煩....
重構下-->
壞習慣:
看了就覺得煩....
<%= select_tag :state, options_for_select( [[t(:draft), "draft"],
[t(:published), "published"]],
params[:default_state] ) %>
重構下-->
<%= select_tag :state, options_for_post_state(params[:default_state]) %>
# app/helpers/posts_helper.rb
def options_for_post_state(default_state)
options_for_select( [[t(:draft), "draft"], [t(:published), "published"]],
default_state )
end