remote_form_for and

Hi there(i'm new to rails, so please be patient =D),

i'm facing some problems with forms and ajax =/ hope someone can help
me, because i was searching here and on the api docs, but no luck then

I believe that i'm missing something...

I have a form_remote_for, and i want it to submit my form in a ajax
request.
Ok!

but the page is still refreshing when i make the submit...

how do i make the submit the right way? i don't think i'm doing it right
using 'p.submit'

So, if someone can explain to me how to do this, or lead me at the right
way

Thanks,

Andreh

//new.html.erb

<% javascript_include_tag(:all) %>

<div id="posts">
  <% for posts in @user.posts %>

     <%= posts.description %> <br />
  <% end %>
</div>

<% form_remote_for :post, @post, :url => { :action => 'create' } do

p> %>

  Post:<br />
  <%= p.text_area :description %>
  <%= p.submit 'Post!' %>
<% end %>

// the controller
def create
      @user = User.find_by_name(params[:name])
      @user.posts << Post.new(params[:post])
      respond_to do |format|
        if (@user.save)
            flash[:notice] = "ok!"
            format.html { render :action => 'show' }
        else
          format.html

        end
      end
  end

Use <%= submit_tag “Post!” %>

Have you tried debugging the page with Firebug? It almost sounds to
me like you would want to take a look a the network calls and make
sure you are getting all of the JS files.

Just my 2c

JW

ops! i figured it out!
when i saw on firebug that i was getting no js calls
i went to look at my javascript_include_tag, i just saw that i missed
the '=' on the <%=

.. beginners mistake.. sorry..
and thanks for the help about how to submit the form!

Hi, another thing, now my page looks like the following:

But, i don't know why, the form_remote_for block, is being duplicated
everytime i click on submit_tag, and the post_wall div isn't being
updated =/
there is form_remote_for just like mine on the Rails Way book... so i
don't know why it doesn't get updated! and duplicates teh post for...

Thanks for the patience again!

<div id="form_post">

<% form_remote_for :post, @post, :update => 'post_wall', :url => {
:action => 'create' } do |p| %>
  Post:<br />
  <%= p.text_area :description %>
  <%= submit_tag 'Post!' %>
<% end %>
</div>
<div id="post_wall">
  <% for posts in @user.posts.reverse %>
     <%= posts.description %> <br />
  <% end %>
</div>

Don’t know what to tell ya, I am looking over the snippet of code and nothing is popping out as far I can see.

Check the DOM and see if the flow is correct. could be as simple as a missing “/” or missing closing tag for a div.

JW

Are you sending the form back in the ajax request? I think this might be what you’re doing, because you’re updating the div post_wall (which is inside the form) which will keep putting the form back in there.

I'm doing this in my action:
  def create
      @user = User.find_by_name(params[:name])
      @user.posts << Post.new(params[:post])

      respond_to do |format|
        if (@user.save)
            flash[:notice] = "Post criado com sucesso"
            format.html { render :action => 'show' }
        else
          format.html

        end
      end
  end

I believe you're correct, i'm sending the form back on the div, have any
idea of what i could do? i'm kinda lost now..

Ryan Bigg wrote:

Hi,

I'm still having trouble to solve this... anyway i don't know how to use
the respond_to without sending the form back for my div..

i saw an example just like this on the Rails Way book, but i couldn't
make it work...

i just don't know how to solve this...

Thanks for the help,