表单中的 Rails 复选框决定控制器中的创建操作?
我正在尝试在创建表单的底部添加一个选择框,以决定是否从控制器运行操作...这是否有意义?
基本上,每当创建新项目时,应用程序都会在 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'
知道我做错了什么吗?
I am trying to add a select box to the base of my create form that decides if an action runs from the controller...if that makes any sense?
Basically the application creates a project in FreeagentCentral whenever a new project is made:
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
and within my form I have:
<%= check_box_tag :send_to_freeagent, 1 %> Create project in Freeagent?
What I would like to happen, is if the select box is checked the project is sent to Freeagent. If not, the case just gets created locally as normal but without the Freeagent data being sent.
If I use the above code, I get an exception caught error:
SyntaxError in KasesController#new
controllers/kases_controller.rb:114: syntax error, unexpected '\n'
Any idea what I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会用
I'd use