Rails:remote => trueがどのように機能するかを理解するために、1日かけてホイールを回転させました。以下の質問は複雑に見えますが、私が提供する情報を使用して、この単純な質問を理解しようとしています。
:remote => trueを使用せずにJSとしてレンダリングするだけのAjax呼び出しを行うにはどうすればよいですか? 私の理解では、:remote => trueは単にAJAX呼び出しを生成して処理します:
私の見解は次のようになります。
- 非常に複雑な方法で選択し、:remote=>trueでリンクを作成します。簡単にするためにこれは省略されています
.e_list = opts.sort_link(:name) = opts.sort_link(:description) - e_list.each do |e| .entry = link_to(e.name, '#', class: 'select_e', data: {e_id: e.id}) = e.description = paginate e_list, remote: true, params: {search:"j", com_id: com.id}
Gallery.js.erb
$('#com<%= @com.id %>').replaceWith('<%= escape_javascript render(partial: "shared/com", locals: {com: @com}) %>');
私のコントローラー:
def gallery
if params[:com_id]
@com = @s.com.find(params[:com_id])
@com.filter = params
end
if c = @s.com.where(:_type => "Com").first
@current_e = c.entries(@user.app_id).first
@current_e.og_url = view_context.og_url(@current_e)
end
render :text => "foobar" if !@current_e
end
ログ、ユーザーがページネーションリンクまたはソートリンクをクリックした後(重要なのは、これらのリンクに:remote => trueがあることです)
Started GET "super long url" for 127.0.0.1 at 2012-05-04 16:08:42 -0700
Processing by CController#gallery as JS
だから私はこれをAJAXで再現しようとします:
$('button.search').live 'click', (e) ->
search = $(e.target).attr('search-term')
success_callback = (results) ->
if results
console.log(results)
update_components(results[0].entry, '.entry')
else
$.ajax(
url: 'super long url that is exactly the same url as above!'
).done ->
return false
JSとしてレンダリングされない私の失敗した応答、それでも私は考えました:remote =>trueは単にajax呼び出しwtfでしたか?:
Started GET "super long url identical as the one that renders JS" for 127.0.0.1 at 2012-05-04 16:07:22 -0700
Processing by ContestController#gallery as */*
何が起こっている?:remote => trueを使用せずにJSとしてレンダリングするだけのAjax呼び出しを行うにはどうすればよいですか?