开发者

show_for gem gives to_key error

开发者 https://www.devze.com 2023-03-07 12:49 出处:网络
hi i am using show_for gem and it gives me error like:undefined method `to_key\' for # in app/views/messages/index.html开发者_JAVA百科.erb where line #46 raised:

hi i am using show_for gem and it gives me error like: undefined method `to_key' for # in app/views/messages/index.html开发者_JAVA百科.erb where line #46 raised:

my view look like these:

46:   <%= show_for @messages do |s|  %>
47:     <%= s.attribute :subject  %>
48:     <%= s.attribute :message %>
49:   <% end %>

my controller code look like:

@messages= Message.all

please help me what i am doing wrong. thanks in advance


I do not know this gem but according to its documentation, show_for is not supposed to receive a collection as argument (@messages) but a single object. I might be wrong.

With this supposition, I would to :

<% @messages.each do |message| %>
  <%= show_for message do |s|  %>
    <%= s.attribute :subject  %>
    <%= s.attribute :message %>
  <% end %>
<% end %>
0

精彩评论

暂无评论...
验证码 换一张
取 消