Ruby on Rails Saturday, September 8, 2018



On Saturday, September 8, 2018 at 12:50:33 PM UTC-4, Walter Lee Davis wrote:
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

> On Sep 8, 2018, at 10:58 AM, fugee ohu <fuge...@gmail.com> wrote:
>
> 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? 

--
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-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6ba94744-42bd-4839-b3f6-6df1ec7e8ccc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment