gpt4 book ai didi

ruby-on-rails-3 - 导轨 3 :mobile MIME type throws 406 error after attempt to load content with JavaScript

转载 作者:行者123 更新时间:2023-12-03 17:57:47 25 4
gpt4 key购买 nike

我正在关注 Railscast #199允许在移动浏览器中查看我的网络应用程序。它工作得很好,除非我尝试在移动版本中使用 UJS 访问选项卡式界面中的信息。单击选项卡在 Web 应用程序中有效,但在移动端我收到 406 错误。 (我在 Safari 中将用户代理设置为 iPhone 后尝试了这个。我还在 iOS 模拟器和我的 iPhone 上进行了测试。都没有加载任何东西。)

下面是其中一个选项卡的一些代码。任何人都可以帮助我定位正在发生的事情吗?这是我的代码。

这是 profiles_controller.rb 中的 profile_about 操作:

def profile_about
@profile = Profile.find(params[:id])
respond_to do |format|
format.js { render :layout => nil }
end
end

在我的 profiles/show.mobile.erb (这与 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 -->

(注意:我有 profiles/_profile_about.html.erbprofiles/_profile_about.mobile.erb 的文件。)

这是我的 profiles/profile_about.js.erb :
$("#tabs-1").html("<%= escape_javascript(render(:partial => 'profile_about'))%>");

我的 Heroku 日志显示 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

从运行 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

最佳答案

您的代码中存在一些错误,可能只是这里的 stackoverflow 格式,但内部引号应该是 ' 而不是 ",如下所示:

$("#tabs-1").html("<%= escape_javascript(render(:partial => 'profile_about'))%>");

这条线引发了您的错误:
format.mobile.js {render :layout => nil}

这是不可能的,因为请求只能有一个 MIME 类型。 “移动”或“js”,而不是两者。如果您从 javascript 请求“profile_about”操作,那么您必须使用 js 响应它。 “format.mobile”应该只用于呈现“profile_about.mobile”模板。

希望这至少是您朝着正确方向迈出的一步。

关于ruby-on-rails-3 - 导轨 3 :mobile MIME type throws 406 error after attempt to load content with JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8427531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com