2015-07-12 50 views
1

不知道我是否以正确的方式进行,但我在我的模型中有以下内容,并希望在我的视图中呈现它(即显示左侧打开的学生空间的数量)如何在我的视图中渲染我定义的模型?

型号:

def open_student_spots 
       event.student_rsvp_limit - event.student_rsvps_count 
    end 

这是我想在我的意见显示,这里的面积就是我做了(虽然不正确,到目前为止)

 <i class='fa fa-user'></i>Spaces Available: <%= 
    <% if event.students_at_limit? %> 
     (<%= event.student_waitlist_rsvps_count %> Waitlisted) 
     <% else %> 
    <% open_student_spots %> #how to fix this line? 
    </div> 
<% end %> 

我怎样才能使这项工作吗?

+0

我有一个感觉,这是错误的'event.student_rsvp_limit - event.student_rsvps_count'。 – Pavan

回答

1

它应该是:

<%= event.open_student_spots %> 

1)使用=来表示输出。

2)它是模型上的一个方法,所以你应该在事件实例中调用它。 (其本身应该可能是一个实例变量,而不是本地变量)

+0

谢谢,这工作! – asaignment

1

你应该给它像<%= event.open_student_spots %>显示在视图中。

小记:

<% %> # Executes the code. 

<%= %> # Prints the output. 
+1

谢谢 - 这工作。我将在未来记住这个音符! – asaignment

相关问题