0

1.我想在视图页面设置GroupMessage模型的形式,group/show/:id。

2.我尝试了下面的代码。

(show.html.erb-group)

<%= form_for([@group, @group_messages]) do |f| %>
<% if @group_message.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@group_message.errors.count, "error") %> prohibited this group_message    from being saved:</h2>
<ul>
<% @group_message.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :member_id %><br />
<%= f.number_field :member_id %>
</div>
<div class="field">
<%= f.label :content %><br />
<%= f.text_area :content %>
</div>
<div class="actions">
<%= f.submit %>
</div> 
<% end %>

(groups_controller)

def show
    @group = Group.find(params[:id])
    @group_message = @group.group_messages.build
    if !checklogin? then return end
        groupfriends = GroupInMember.where(:member_id => session[:login].id)
         gflist = '('
        groupfriends.each do |gf|
         gflist += gf.member_id.to_s + ","
        end
      gflist += session[:login].id.to_s + ')'
       @query = "select * from group_messages where member_id in " +  gflist 
       @group_messages = GroupMessage.find_by_sql(@query)
respond_to do |format|
format.html # index.html.erb
format.json { render json: @group_messages }
end
end

3.然后我得到一个错误。未定义的方法 `group_messages' 用于#

4.我该如何解决这个问题??

4

1 回答 1

0

我的猜测是,@group = Group.find(params[:id])它没有返回一个Group.

于 2013-09-26T06:29:22.023 回答