【问题标题】:Rails 4 view Helper: wrong number of argumentsRails 4查看助手:参数数量错误
【发布时间】:2014-06-12 09:42:20
【问题描述】:

我正在将项目从 rails 3 升级到 rails 4。当我切换到 rails 4 时,我在日志中遇到了这个错误。但是我没有向这个方法传递任何参数。

ActionView::Template::Error (wrong number of arguments (1 for 0)):
    1: <div id="titles_list">
    2:
    3:   <div id="admin_title_select_group">
    4:     <% table_group = select_table_group %>
    5:     <%= select_tag 'selected_group', options_for_select(table_group, by_default_selected_group) %>
    6:   </div>
    7:
  app/helpers/admin/titles_helper.rb:14:in `select_table_group'
  app/views/admin/titles/index.html.erb:4:in `_app_views_admin_titles_index_html_erb__3791160006166460542_70179046974220'
  lib/metal/search_store.rb:17:in `call'

index.html.erb

<div id="titles_list">

  <div id="admin_title_select_group">
    <% table_group = select_table_group %>
    <%= select_tag 'selected_group', options_for_select(table_group, by_default_selected_group) %>
  </div>
...

这是我的辅助方法:

module Admin::TitlesHelper

  def select_table_group
    g = [[I18n.t('admin.tpgn.select_group'),0]]
    g += TitleProviderGroupName.all(:order => :name).collect{|t| [ t.name, t.id ]}

  end

  def by_default_selected_group
    if params[:tpgn_id]
      params[:tpgn_id]
    else
      0
    end
  end

end

它在 rails 3 中运行良好。rails 4 中的 helper 方法有什么变化吗?我没有找到任何相关信息。

【问题讨论】:

  • titles_helper.rb 中的哪一行是第 14 行?
  • g += TitleProviderGroupName.all(:order =&gt; :name).collect{|t| [ t.name, t.id ]} 啊,谢谢提醒,我还以为是Model.all不接受参数的问题。

标签: ruby-on-rails ruby-on-rails-4 view-helpers


【解决方案1】:

all 方法在 Rails 4 中不接受参数。

TitleProviderGroupName.all

必须改成

TitleProviderGroupName.order(:name)

【讨论】:

  • 谢谢,我找到了:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-19
  • 1970-01-01
  • 2021-11-08
  • 1970-01-01
相关资源
最近更新 更多