我想使它在這裏這種形式將顯示基於網站的類型某些領域。在這種情況下,我希望它顯示project.type == Website時的表單。查看不識別模型屬性? Rails
不過,我不斷收到
undefined method `type' for #<Project::ActiveRecord_Relation:0x007ffe1cb543a8>
我相信,我可以正常調用.TYPE,因爲它工作在控制檯中。
這裏是我的文件:
#views/assets/_new_asset.html.erb
<%= simple_form_for @asset do |f| %>
<% if @project.type == 'Website' %>
<%= f.input :name %>
<%= f.input :url %>
<%= f.button :submit %>
<% end %>
<% end %>
這裏是我的資產/控制器
#controller/assets_controller.rb
class AssetsController < ApplicationController
def new
@asset = Asset.new
project = Asset.where(:project_id)
@project = Project.where(:id == project)
end
def create
@asset = current_user.assets.build(asset_params)
if @asset.save
flash[:notice] = "Asset successfully added."
redirect_to(@project, :action => 'show')
else
render(:action => 'new')
end
end
private
def asset_params
params.require(:asset).permit(:id, :type,:url, :page_rank, :rev_company ,:social_pages)
end
end
先給這樣'<%@如果project.first.type == '網站' %>' – Pavan
我認爲你的@project是一個項目的集合,你需要循環它,然後尋找它的類型 – Mandeep