Rails select box in form decides on create action in controller?
Posted
by dannymcc
on Stack Overflow
See other posts from Stack Overflow
or by dannymcc
Published on 2010-06-14T20:20:06Z
Indexed on
2010/06/14
20:22 UTC
Read the original article
Hit count: 257
Hi Everyone?
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, also is it possible to make the check boxes checked as default?
Thanks,
Danny
© Stack Overflow or respective owner