我正在使用 Rails 4 制作应用程序。我对表格使用简单的表格。
我正在制作在表单输入上显示略有不同标签的演示者。
我使用它们如下:
在表格中:
<%= f.input :description, :as => :text, :label => " <%= @project_presenter.description %> ", :input_html => {:rows => 10} %>
在演示者中:
class ProjectPresenter
def initialize(project, profile)
@project = project
@profile = user.profile
end
def description
if student?
"What does the project involve? "
elsif sponsor?
"Describe the project. "
elsif educator?
"What does the project involve? How will students be involved in the project? "
elsif researcher?
"What's involved in the project? Describe the issues to be addressed."
end
end
当我尝试这个时,我得到一个指向这一行的语法错误:
<%= f.input :description, :as => :text, :label => " <%=
@project_presenter.description %> ", :input_html => {:rows => 10} %>
我认为它不希望演示者周围有 <%= %> 标记。
您如何在表单中使用演示者?
Presenter 定义为:
class ProjectPresenter
def initialize(project, profile)
@project = project
@profile = user.profile
end
def description
....
end
用户模型中的关联是:
has_many :articles
has_many :authentications, :dependent => :delete_all
has_many :comments
belongs_to :organisation
has_one :profile
has_many :qualifications
has_many :identities
has_many :trl_assessments, as: :addressable
has_and_belongs_to_many :projects