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) %>

<% for posts in @user.posts %>
 <%= posts.description %> <br />

<% end %>

<% form_remote_for :post, @post, :url => { :action => ‘create’ } do
|p| %>
Post:

<%= 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!” %>

On Jan 24, 2008 9:52 AM, Andreh L. [email protected]
wrote:

request.
Thanks,

<% end %>
format.html

   end
 end

end

Posted via http://www.ruby-forum.com/.


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

looks like the same with submit_tag
the page stills do a refresh…
like it is without ajax

Thanks!

Ryan B. wrote:

Use <%= submit_tag “Post!” %>

On Jan 24, 2008 9:52 AM, Andreh L. [email protected]
wrote:

request.
Thanks,

<% end %>
format.html

   end
 end

end

Posted via http://www.ruby-forum.com/.


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

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

On Jan 23, 6:43 pm, Andreh L. [email protected]

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!

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

On Jan 23, 2008 8:06 PM, Andreh L. [email protected]

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.

On Jan 24, 2008 11:46 AM, Jason W. [email protected] wrote:

wrote:

Thanks for the patience again!

<% for posts in @user.posts.reverse %> <%= posts.description %>
<% end %>
-- Posted via http://www.ruby-forum.com/. > >


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

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!

<% form_remote_for :post, @post, :update => ‘post_wall’, :url => {
:action => ‘create’ } do |p| %>
Post:

<%= p.text_area :description %>
<%= submit_tag ‘Post!’ %>
<% end %>

<% for posts in @user.posts.reverse %> <%= posts.description %>
<% end %>

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 B. wrote:

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.

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,

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs