V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
shooter
V2EX  ›  程序员

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

  •  
  •   shooter ·
    rebase-network · 2011-11-30 14:54:07 +08:00 · 5000 次点击
    这是一个创建于 4502 天前的主题,其中的信息可能已经有所发展或是发生改变。
    除了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
    蛋都碎了
    10 条回复    1970-01-01 08:00:00 +08:00
    roamlog
        1
    roamlog  
       2011-11-30 14:55:39 +08:00
    错误信息最好全一点。。。
    tysx
        2
    tysx  
       2011-11-30 14:59:05 +08:00
    给url加上后缀,例如.xml, .html试试
    shooter
        3
    shooter  
    OP
       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
        4
    roamlog  
       2011-11-30 15:11:39 +08:00
    我是要看错误信息,不管是在终端的还是 log 文件里的
    shooter
        5
    shooter  
    OP
       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
        6
    shooter  
    OP
       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
        7
    chloerei  
       2011-11-30 15:32:57 +08:00
    start authorize 是什么?用了什么插件?
    shooter
        8
    shooter  
    OP
       2011-11-30 15:47:11 +08:00
    @chloerei ApplicationController.rb定义的一个方法
    貌似跟这有关
    UsersController.rb
    skip_before_filter :authorize, :only => [:index, :show, :list,]
    tysx
        9
    tysx  
       2011-11-30 18:43:29 +08:00
    把 GET "/users/new" 改成GET "/users/new.html"或者GET "/users/new.json"
    也不行吗?
    shooter
        10
    shooter  
    OP
       2011-12-01 10:32:02 +08:00
    @tysx 不可以 这个问题解决了 定义了authorize method 在ApplicationController.rb

    关键这里 skip_before_filter :authorize, :only => [:index, :show, :list,]
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5566 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 06:06 · PVG 14:06 · LAX 23:06 · JFK 02:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.