How to make a respond_to by AJAX in Rails 3?

我是研究僧i 提交于 2019-12-22 01:22:41

问题


I have a form, that I send with using AJAX. The form is in the FirstsController. I need the form send to SecondsController. The form is sent and data saved. Then I wanna change the form by a text, I try to do by this way:

  def create
   ...saving...

    respond_to do |format|
      format.js { 
        render :update do |page|; page << "$('#id_element').html('hellllloooooo');" end  
       }
      format.html {} 
    end
  end

And I ma getting this error:

ActionView::MissingTemplate (Missing template seconds/update, application/update with {:handlers=>[:erb, :builder, :coffee], :formats=>[:js, :html], :locale=>[:en, :en]}.):

How should I set the JS request back to the FirstsController? + is needed any help *.js file?


回答1:


This is the right set up to do it:

 def create
   ...saving...

    respond_to do |format|
      format.js { 
        render 'firsts/action_that_you_want' 
       }
      format.html {} 
    end
  end

And in the FirstsController is needed to have created the the file action_that_you_want.js.erb.



来源:https://stackoverflow.com/questions/9042155/how-to-make-a-respond-to-by-ajax-in-rails-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!