こんにちは、form_remote_for の送信タグで JavaScript 関数呼び出しを使用しようとしましたが、呼び出している関数を見つけることができません。form_remote_for から同じ関数を呼び出すと、ajax が機能しなくなります。form_remote_for NOT FORM_REMOTE_TAG を使用しているときに JavaScript 関数を呼び出す方法を教えてください。
3163 次
1 に答える
1
REMOTE_FORM_FOR が必要だと思います。
例:
あなたの見解では:
<%- 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 -%>
注意: :after の JavaScript 関数は、私のカスタム JavaScript 関数です。
そしてあなたのコントローラーで(ここではcomments_controllerです)
@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
とにかく簡単なサンプルなので、remote_form_for の感覚を掴んでから詳細を処理する必要があります。
幸運を。
于 2009-05-23T07:27:10.770 に答える