Form_remote_for in rails

HI I tried to use a javascript function call in the submit tag form_remote_for but couldn't find the im call function. if i call the same function from form_remote_for then ajax stops working. can help me how can i call the javascript function when i use form_remote_for NOT FORM_REMOTE_TAG .... ????

0


a source to share


1 answer


I think REMOTE_FORM_FOR is what you need.

Example:

In your opinion:

<%- remote_form_for(comment, :url => topic_post_comments_path(@topic, post), 
           :after => "submitComment(self);$('input').disable()") do |f| %>
<%= f.text_field :body, :size => 70, :class => "comment_body" %><br />
<%= f.submit "Submit", :class => "comment_submit" %>
<%- end -%>

      

Please note the javascript function in: after my custom javascript functions.



And in your controller (comment_controller is here)

@comment = @post.comments.new params[:comment] # actually, it depends on your model :p

respond_to do |format|
  # remember to handle exception here. like if @comment.save or not
  format.html
  format.js { 
    render :update do |page|
      pagepage.visual_effect :highlight, "comments"
    end
  }
end

      

this is just a simple example anyway, you need to process more details after you get a sense of the distant_formaton.

Good luck.

+1


a source







All Articles