The Rails guide has a great write-up on
this:
http://guides.rubyonrails.org/working_with_javascript_in_rails.html#form-for
Essentially, remote: true will handle submitting your form via ajax for
you, but it's on you to handle the response (since that's going to be very
application-specific). In your case, if the tweets are displayed in a
list, maybe the action responds to ajax requests by rendering just a tweet
template (versus the entire tweets collection), and your JS takes that HTML
snippet and inserts it into the list.
On Sunday, March 13, 2016 at 4:26:51 PM UTC-4, Ruby-Forum.com User wrote:
>
> Dear community,
>
> I have a small concern about remote true.
> I am building simple twitter site. Let's say user has "tweet" from on
> the main page and a list of tweets below.
>
> here is what I do:
> <%= form_tag("/tweets", method: "post", class: "new-tweet") do %>
> <%= label_tag(nil, "New tweet") %>
> <%= text_field_tag(:text,nil,remote:true, placeholder: "Enter your
> tweet message here. Limit 140 symbols", maxlength: 140) %>
> <%= submit_tag("Tweet") %>
> <% end %>
> <div class="tweets">
> <% if @tweets %>
> <% @tweets.each do |tweet| %>
> <div class="tweet"><%= tweet.text %></div>
> <% end %>
> <% end %>
> </div>
>
> route /tweets leads to another controller which actually adds a tweet to
> the users collection which is displayed on the main page. My question
> is: Does it make sense to use "remote: true" in the form here in order
> to not reload all page.
>
> If my question does not make sense, here is a deal. How does
> "remote:true" actually works and what benefits does it give?
>
> --
> Posted via http://www.ruby-forum.com/.
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/32dbbd79-7467-4733-9b7a-6216943d8077%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.