在group / show /:id(view)的页面上设置GroupMessage模型的形式

时间:2013-09-26 06:19:32

标签: ruby-on-rails ruby ruby-on-rails-3.2 erb

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

我试过下面的代码。

(show.html.erb组)

<%= 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

然后我收到了一个错误。 用于#

的未定义方法`group_messages'

4.我怎么解决这个问题?

1 个答案:

答案 0 :(得分:0)

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