Tag: 重定向

重定向适用于登录但不适用于注销

说明 我正在使用带有Ruby on Rails webapp的devise gem,并按照本教程介绍如何在用户登录和注销后将用户重定向回上一页。 问题是,代码似乎适用于登录部分,但注销总是将用户重定向到root_path。 题 当我完全按照教程,并且重定向适用于一个,我是否错过了一个错字或者其他地方的代码是否覆盖了这段代码? 使用的版本 Ruby:ruby 2.2.1p85(2015-02-26修订版49769)[x86_64-darwin14] Rails:Rails 4.2.0 设计:3.4.1 码 应用控制器: ## app/controllers/application_controller.rb class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception after_filter :store_location before_action :configure_permitted_parameters, if: :devise_controller? def store_location # store last […]

重定向发出PATCH请求而不是GET

我正在从我的application.js文件中发出一个ajax补丁请求: $.ajax({ type: “PATCH”, url: “/units/” + id, data: { ‘var_1’: var_1, ‘var_2’: var_2,}, success:function(){ alert(“Details saved successfully!!!”); }, dataType: “text” }); // stop normal form submission behaviour $(“#add_form”).submit(function(e){ return false; }); 我的控制器成功接收到此请求,并更新了我的对象的属性。 然后我尝试重定向到具有特定id的索引页面。 units_controller.rb if @unit.update_attributes( ** data ** ) flash.notice = “Successfully updated ” redirect_to :controller => “/units”, :action => “index”, :id => […]

如何在Rails 3中使用AJAX请求实现重定向响应?

我有一个简单的场景,我想要一个页面。 请求格式是AJAX。 如果该请求的控制器/操作逻辑中存在一些错误,我想重定向到错误页面。 问题是重定向不是JavaScript响应类型,所以我不确定它是否会起作用。 如果没有错误,那么我希望通过适当的JavaScript响应类型更新页面。 考虑到请求格式是AJAX,实现重定向响应的最佳做法是什么?

页面没有正确地重定向Ruby on Rails

出于某种原因,我在点击页面的受保护部分时收到错误: Firefox:页面未正确重定向 这是我在ApplicationController使用的方法: protected def authorize unless User.find_by_id(session[:remember_token]) flash[:notice] = “Please Log in” redirect_to :controller => ‘sessions’, :action => ‘new’ end end 出于某种原因,我无法访问sessions/new ,这是我的登录页面。 任何帮助将非常感谢。 我检查了路线,我得到了sessions/new 。

Rail 3:重定向后实例变量不可用

我在Rails 3中有一个表单向导。基本上,我创建了一个酒店对象,然后当所有这些完成后,我想为该酒店创建一个位置对象。 我创建酒店的控制器代码如下所示: def create @hotel = Hotel.new(params[:hotel]) respond_to do |format| if @hotel.save @location = Location.new format.html { redirect_to ‘/set_location’} else format.html { render action: “new” } end end end 然后在’/ set_location’页面中,我有一个设置位置的表单。 但是,我在html.erb上为@location实例变量获取了一个’undefined method model_name for NilClass:Class’错误。 这真的很奇怪,因为当我使用render’/ set_location’而不是redirect_to然后它工作正常。 但是,我想使用redirect_to方法以防止重复记录提交。 在此先感谢任何帮助。

如何在heroku上重定向域?

我有一个专为stuff.heroku.com上的多个用户设计的应用程序 登录页面可能看起来像stuff.heroku.com/controller/1/action/73 但是我想在那里重定向的url看起来像sub.domain.com/hello 同样,我可能希望sub.domain.com/greetings指向另一个登录页面,这次是在stuff.heroku.com/controller/1/action/74。 一旦有效,我会希望sub.anotherdomain.com/hello映射回我的同一个应用程序,例如stuff.heroku.com/controller/1/action/87 我怎样才能做到这一点?

如何重定向到root – public / index.html?

我希望在我的应用程序/公共文件夹中重定向到index.html。 def get_current_user @current_user = current_user if @current_user.nil? redirect_to root_path end end 我该如何实现这一目标? 我没有修改我的routes.rb中的根(它仍然评论) # root :to => “welcome#index” 我收到一个错误,说root_path未定义。 如何修改routes.rb以便root_path指向public / index.html?

成功进行DEVISE登录后,如何将用户重定向回以前需要登录的操作?

我有一个ajax投票按钮:如果用户点击“竖起大拇指”图像,但没有登录,那么他们应该会看到一个对话框,要求他们先登录。 要执行此对话框,我使用jQuery和facebox绑定到ajax:failure事件。 如果用户未登录,Devise将引发401 Unauthorized .facebox在弹出对话框中加载远程html以进行登录,该对话框显示DEVISE登录表单。 一切正常,除非成功登录后,用户被重定向到主页。 如果用户被重定向回他们正在查看的post以便他们可以继续投票,那将更直观。 是否有实现此行为的最佳实践方法? 谢谢。

Rails:我无法在重定向中传递validation错误

所以这是一个简单的项目,有产品,你可以出价。 想想eBay。 我按如下方式构建了项目: $ rails new routetest $ rails g scaffold product productname reserveprice:integer $ rails g scaffold bid bidprice:integer product_id 在我所包含的每个产品的“展示”视图中 产品详情(由脚手架产生) 到目前为止的出价列表 使用form_for帮助程序汇总新出价的表单 Normal Products\Show Part Productname: Reserveprice: List of bids Product ID Bid Price Form For Bids Make a Bid (params[:id]) %> 点击“提交”后,将调用出价控制器#create action。 def create @bid = Bid.new(bid_params) if @bid.save redirect_to […]

链接回到表单之前访问的页面

我有一个列表页面,然后是表单,然后是感谢页面。 我需要在感谢页面上放置一个链接,该链接将用户带回到他们所在的页面之前,该表单始终有所不同。 我试过用这个: = link_to “Back”, :back 但这只会让他们回到上一页,所以表格。