respond js different controller

I wanna modify the dom on the coversations show page which contains a new message form for the messages controller Presently the create action in the messages controlller redirects to conversations/show I wanna respond js with simply render conversations/show Can I do that?

Yes, you can. If you have the respond_to block in the controller, then anything you put inside the block can do whatever it wants to. Here's one from a controller I made some time ago with the scaffold generator:

  def update     respond_to do |format|       if @country.update(country_params)         format.html { redirect_to @country, notice: 'Country was successfully updated.' }         format.json { render :show, status: :ok, location: @country }       else         format.html { render :edit }         format.json { render json: @country.errors, status: :unprocessable_entity }       end     end   end

Only one block will respond to the action here, depending on the format and the result of #update. So this won't violate the single render/redirect constraint on controller method.

At the Ruby level, this is just a block inside a block.

Walter

Yes, you can. If you have the respond_to block in the controller, then anything you put inside the block can do whatever it wants to. Here's one from a controller I made some time ago with the scaffold generator:

  def update     respond_to do |format|       if @country.update(country_params)         format.html { redirect_to @country, notice: 'Country was successfully updated.' }         format.json { render :show, status: :ok, location: @country }       else         format.html { render :edit }         format.json { render json: @country.errors, status: :unprocessable_entity }       end     end   end

Only one block will respond to the action here, depending on the format and the result of #update. So this won't violate the single render/redirect constraint on controller method.

At the Ruby level, this is just a block inside a block.

Walter

> > I wanna modify the dom on the coversations show page which contains a new message form for the messages controller Presently the create action in the messages controlller redirects to conversations/show I wanna respond js with simply render conversations/show Can I do that? > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com. > To post to this group, send email to rubyonra...@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/efcc9162-a8f3-4d9c-98ff-690dfc04530f%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout.

I think respond_to within the action and respond js are different but a separate subject I put respond js at the top of the controller and created a create.js.erb view At the end of the create action there's nothing in substitution of repsond_to do |format| I'm just expecting it to render create.js.erb (in the messages controller still) and then the content of create.js.erb is gonna be $("#conversation_area").html("<%=j render('conversations/show') %>")     Does that make sense?

Try using the long-hand, not the shortcut of using respond js at the top. The long-hand is what the shortcut becomes eventually, so it's clearer why it works that way. Yes, you will have to put a separate format.js in each method, but when you do that, you can see exactly what it is doing, and make each method respond the way you want it to.

Walter