call controller with ajax in rails -
in ruby on rails project, when create reporter successfully, page redirect action controller; , when page redirect, page reloaded. in project, have 2 controller:
reporters_controller.rb:
class reporterscontroller < applicationcontroller layout "reporter" def new @reporter = reporter.new @gomrokaddresses = gomrokaddress.find(:all) end def create @reporter = reporter.new(reporter_params) if @reporter.save #redirect_to new_reporter_path redirect_to new_problem_path(:id => @reporter.id) else @existreporter = reporter.find_by(params[:rep_user_name]) redirect_to new_problem_path(:id => @existreporter.id) end end
problems_controller.rb
def new @reporter = reporter.find(params[:id]) @problem = @reporter.problems.build end def create @reporter = reporter.find(params[:id]) @problem = @reporter.problems.build(problem_params) if @problem.save redirect_to new_problem_path(:id => @reporter.id) else redirect_to new_problem_path(:id => @reporter.id) end end
reporter.rb
class reporter < activerecord::base has_many :problems end
problem.rb
class problem < activerecord::base belongs_to :reporter end
i create reporter , problem form_for
in view. when complete form_for
in new.html.erb
(for reporter) , submit, create action (that exist in reporter_controller) called, , if information true, page redirect /problems/new
. because of redirect_to
, page reload; don't want reload page, when create reporter, form_for
of reporter replace form_for
of problem. how can this?
try in controller
redirect_to new_problem_path(:id => @reporter.id), format: 'js'
hope helps!
Comments
Post a Comment