rails3 406 browser Internet Explorer 无法读取此网页格式

2011-11-30 14:54:07 +08:00
 shooter
除了show 其他的页面都无法访问

Started GET "/users/new" for 127.0.0.1 at 2011-11-30 14:50:41 +0800
Processing by UsersController#new as HTML
start authorize
Completed 406 Not Acceptable in 0ms
蛋都碎了
5236 次点击
所在节点    程序员
10 条回复
roamlog
2011-11-30 14:55:39 +08:00
错误信息最好全一点。。。
tysx
2011-11-30 14:59:05 +08:00
给url加上后缀,例如.xml, .html试试
shooter
2011-11-30 15:03:39 +08:00
user_controller.rb
def new
@user = User.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @user }
end
end

def create
#if request with JSON, which means multi-part will be used
logger.debug "create...."
logger.debug request.headers['Accept']
if(request.headers['Accept'] == "application/json")
data = ActiveSupport::JSON.decode(params[:user])
@user = User.new(data)
else
@user = User.new(params[:user])
end
respond_to do |format|
if @user.save
format.html { redirect_to(users_url, :notice => "User #{@user.name} was successfully created.") }
#format.json { render json: @user, status: :created, location: @user }
#format.json { render :json => @user.as_json(:only => [:name])}
#render :nothing => true
format.json {render json: @user.as_json(:only => [:id, :hashed_password])}
else
format.html { render action: "new" }
format.json { render json: @user.errors}# status: :unprocessable_entity }
end
end
end
--------------------------------------------------------------------------------------------------------
new.html.erb
<%= form_for(@user, :html => { :multipart => true }) do |f| %>
..................................................
<% end>
------------------------------------------------------------------------------
routes.rb
resources :users do
resources :trips do
resources :spots do
resources :photos
end
end
end
roamlog
2011-11-30 15:11:39 +08:00
我是要看错误信息,不管是在终端的还是 log 文件里的
shooter
2011-11-30 15:17:57 +08:00
@tysx@roamlog 不好使 Completed 406 Not Acceptable in 0ms 应该是输出格式的问题
另外 存在 format.json { render json: @trip.errors, status: :unprocessable_entity }
shooter
2011-11-30 15:22:15 +08:00
@roamlog 没有错误信息 不报错 提示信息
Started GET "/users/new.html" for 127.0.0.1 at 2011-11-30 15:19:26 +0800
Processing by UsersController#new as HTML
start authorize
Completed 406 Not Acceptable in 0ms

貌似输出格式的问题?? 可没做什么特殊格式处理啊
chloerei
2011-11-30 15:32:57 +08:00
start authorize 是什么?用了什么插件?
shooter
2011-11-30 15:47:11 +08:00
@chloerei ApplicationController.rb定义的一个方法
貌似跟这有关
UsersController.rb
skip_before_filter :authorize, :only => [:index, :show, :list,]
tysx
2011-11-30 18:43:29 +08:00
把 GET "/users/new" 改成GET "/users/new.html"或者GET "/users/new.json"
也不行吗?
shooter
2011-12-01 10:32:02 +08:00
@tysx 不可以 这个问题解决了 定义了authorize method 在ApplicationController.rb

关键这里 skip_before_filter :authorize, :only => [:index, :show, :list,]

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/22498

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX