Tôi đang theo dõi Railscast #199 để cho phép ứng dụng web của tôi được xem trong trình duyệt trên thiết bị di động. Nó hoạt động tốt, ngoại trừ khi tôi cố gắng truy cập thông tin trong một giao diện tab sử dụng UJS trong phiên bản di động. Nhấp vào các tab hoạt động trong ứng dụng web, nhưng ở phía bên thiết bị di động, tôi nhận được lỗi 406. (Tôi đã thử điều này sau khi cài đặt Tác nhân người dùng làm iPhone trong Safari. Tôi cũng đã thử nghiệm trên iOS Simulator và iPhone của tôi. Không phải lúc nào cũng tải bất kỳ thứ gì.)Rails 3: loại MIME di động ném 406 lỗi sau khi thử tải nội dung bằng JavaScript
Dưới đây là một số mã cho một trong các tab. Có ai có thể giúp tôi nhắm vào những gì đang diễn ra không? Đây là mã của tôi.
Đây là hành động profile_about trong profiles_controller.rb
:
def profile_about
@profile = Profile.find(params[:id])
respond_to do |format|
format.js { render :layout => nil }
end
end
Trong tôi profiles/show.mobile.erb
(đây là mã chính xác giống như trong profiles/show.html.erb
):
<div id="tabs">
<ul id="infoContainer">
<li><%= link_to "Cred", profile_cred_profile_path, :class=> 'active', :remote => true %></li>
<li><%= link_to "About", profile_about_profile_path, :class=> 'inactive', :remote => true %></li>
</ul>
<div id="tabs-1">
<%= render :partial => 'profile_cred' %>
</div>
</div><!-- end tabs -->
(Chú ý: Tôi có một tệp cho profiles/_profile_about.html.erb
và profiles/_profile_about.mobile.erb
.)
Đây là tôi profiles/profile_about.js.erb
:
$("#tabs-1").html("<%= escape_javascript(render(:partial => 'profile_about'))%>");
Heroku My đăng nhập hiển thị 406:
2012-03-08T03:02:55+00:00 app[web.1]: Started GET "/profiles/1/profile_about" for 98.218.231.113 at 2012-03-08 03:02:55 +0000
2012-03-08T03:02:55+00:00 heroku[router]: GET myapp.com/profiles/1/profile_about dyno=web.1 queue=0 wait=0ms service=14ms status=406 bytes=1
2012-03-08T03:02:55+00:00 app[web.1]: Processing by ProfilesController#profile_about as JS
2012-03-08T03:02:55+00:00 app[web.1]: Parameters: {"id"=>"1"}
2012-03-08T03:02:55+00:00 app[web.1]: Completed 406 Not Acceptable in 3ms
2012-03-08T03:02:55+00:00 heroku[nginx]: 98.218.231.113 - - [08/Mar/2012:03:02:55 +0000] "GET /profiles/1/profile_about HTTP/1.1" 406 1 "http://myapp.com/profiles/1" "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3" myapp.com
Từ chạy tail -f logs/development.log
:
Started GET "/profiles/1/profile_about" for 127.0.0.1 at Wed Mar 07 22:35:36 -0500 2012
Processing by ProfilesController#profile_about as JS
Parameters: {"id"=>"1"}
PK and serial sequence (5.4ms) SELECT attr.attname, seq.relname
FROM pg_class seq,
pg_attribute attr,
pg_depend dep,
pg_namespace name,
pg_constraint cons
WHERE seq.oid = dep.objid
AND seq.relkind = 'S'
AND attr.attrelid = dep.refobjid
AND attr.attnum = dep.refobjsubid
AND attr.attrelid = cons.conrelid
AND attr.attnum = cons.conkey[1]
AND cons.contype = 'p'
AND dep.refobjid = '"goals_profiles"'::regclass
PK and custom sequence (2.5ms) SELECT attr.attname,
CASE
WHEN split_part(def.adsrc, '''', 2) ~ '.' THEN
substr(split_part(def.adsrc, '''', 2),
strpos(split_part(def.adsrc, '''', 2), '.')+1)
ELSE split_part(def.adsrc, '''', 2)
END
FROM pg_class t
JOIN pg_attribute attr ON (t.oid = attrelid)
JOIN pg_attrdef def ON (adrelid = attrelid AND adnum = attnum)
JOIN pg_constraint cons ON (conrelid = adrelid AND adnum = conkey[1])
WHERE t.oid = '"goals_profiles"'::regclass
AND cons.contype = 'p'
AND def.adsrc ~* 'nextval'
Profile Load (1.3ms) SELECT "profiles".* FROM "profiles" WHERE "profiles"."id" = '1' LIMIT 1
Completed 406 Not Acceptable in 30ms
Bạn đang ở trong môi trường phát triển đúng không? Log/development.log nói gì về 500? – brutuscat
Chỉ cần cập nhật thông tin trong nhật ký của tôi khi tôi nhấp "về" với tác nhân người dùng của iPhone. – tvalent2