Move code into helper

原文參考: http://rails-bestpractices.com/posts/26-move-code-into-helper
壞習慣:
看了就覺得煩....
<%= 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

你可能感兴趣的:(Ruby,Rails)