我正在尝试在我的创建表单的基础上添加一个选择框,它决定一个动作是否从控制器运行......如果这有意义吗?
基本上,无论何时制作新项目,应用程序都会在FreeagentCentral中创建一个项目:
def create
@company = Company.find(params[:kase][:company_id])
@kase = @company.kases.create!(params[:kase])
respond_to do |format|
params[:send_to_freeagent] ? @kase.create_freeagent_project(current_user)
#flash[:notice] = 'Case was successfully created.'
flash[:notice] = fading_flash_message("Case was successfully created.", 5)
format.html { redirect_to(@kase) }
format.xml { render :xml => @kase, :status => :created, :location => @kase }
end
end
在我的表格中我有:
<%= check_box_tag :send_to_freeagent, 1 %> Create project in Freeagent?
我想要发生的是,如果选中此框,则项目将发送给Freeagent。如果没有,案例就会在正常情况下在本地创建,但不会发送Freeagent数据。
如果我使用上面的代码,我会收到异常捕获错误:
SyntaxError in KasesController#new
controllers/kases_controller.rb:114: syntax error, unexpected '\n'
知道我做错了吗?
谢谢,
丹尼
答案 0 :(得分:1)
我用
def create
@company = Company.find(params[:kase][:company_id])
@kase = @company.kases.create!(params[:kase])
@kase.create_freeagent_project(current_user) if params[:send_to_freeagent].to_bool
respond_to do |format|
# ...
end
end