仅在root_path上登录后才重定向用户

我的Rails应用程序上有一个root_path ,它不受用户保护,即它是一个简单的门户网站主页,带有登录表单。 用户登录后,我希望它转到dashboard_path 。 我做到了这个: def signed_in_root_path(scope_or_resource) dashboard_path end 这显然应该在用户登录时使用,并且我不希望它转到root_path ,同时仍然保持用户返回到前一页,如果它尝试到达受限区域并且它要么超时还是没有超时登录。 即: restricted_pa​​ge – > login – > restricted_pa​​ge_but_logged_in 我不想改变这种行为,这就是为什么我没有使用after_sign_in_path ,但是如果它在root_path ,或者想要在不需要用户身份validation的任何路由上重定向它。 我的问题是这不起作用。 登录后,我将被重定向回root_path ,我认为这是因为之前触发了after_sign_in_path 。 有没有办法做到这一点? 谢谢! 编辑:这是我第二次登录时工作,即我转到root_path ,登录,获取闪存消息,说明我已登录,并在root_path上的表单上再次输入用户名和密码。 我成功地被重定向到dashboard_path 。 不过,不是我想要的行为。

rails – 在link_to上传递id参数

我正在尝试将当前页面(id)的参数传递给下一页,以便创建依赖模型条目。 即项目有投标,投标属于项目。 所以在项目的展示页面上我添加了链接 这创建并执行url….“http:// localhost:3000 / bid / new.2” 我有 def new @bid = Bid.new @project = Project.find(params[:id]) end 在出价控制器,但我不断收到错误“无法找到没有ID的项目” ??? 怎么回事,为什么我不能通过身份证?

是否可以像使用Python一样将Ruby编译为字节代码?

在Python中,如果我想提供一个没有源代码的应用程序,我可以将它编译成字节码.pyc,有没有办法在Ruby中做类似的事情?

像Twitter粉丝这样的关系/在ActiveRecord中跟随

我试图在我的应用程序中表示用户之间的关系,其中用户可以拥有许多关注者并且可以关注其他用户。 我想有像user.followers()和user.followed_by()这样的东西你能告诉我如何使用ActiveRecord来表示这个吗? 谢谢。

使用RVM在OSX上安装Rails 3

尝试在OSX 10.6上安装新的Rails 3版本。 自购买以来,从未在这台机器上接触过Ruby或Rails。 我能够获得rvm并获得Ruby 1.9.2。 安装。 从那里,我被卡住了。 我试过了: rvmsudo gem install rails -v 3.0.0 sudo gem install rails –pre sudo gem install rails sudo gem update rails 每次我得到相同的结果错误: ERROR: While executing gem … (Errno::ENOENT) No such file or directory – /Users/kevin/.rvm/gems/ruby-1.9.2-head@rails3/cache/activesupport-3.0.0.gem 如果我做gem清单,它说LOCAL GEMS并没有列出任何东西。 我已经阅读了一些演练,但老实说,他们都没有解决这个问题,这让我感到很生气。 为什么这么难安装? 如果有人可以帮助我让它运行,我很乐意学习它。 我试图遵循这个: http://eddorre.com/posts/installing-rails-3-beta-4-using-rvm 还有这个: http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard 这实际上是从ROR指南网站链接的。 我错过了依赖吗? 我如何让他们进去? 如果我做rails […]

使用Rspec + Capybara在Rails中测试错误页面

在Rails 3.2.9我有自定义错误页面定义如下: # application.rb config.exceptions_app = self.routes # routes.rb match ‘/404’ => ‘errors#not_found’ 哪个效果如预期。 当我在development.rb设置config.consider_all_requests_local = false时,在访问/foo时我得到了not_found视图 但是如何用Rspec + Capybara测试呢? 我试过这个: # /spec/features/not_found_spec.rb require ‘spec_helper’ describe ‘not found page’ do it ‘should respond with 404 page’ do visit ‘/foo’ page.should have_content(‘not found’) end end 当我运行此规范时,我得到: 1) not found page should respond with 404 page Failure/Error: […]

ruby三倍相等

假设我有以下代码。 result = if a.is_a?(Class) && a <= Exception a.name elsif … elsif … end 我重构了这段代码 case a when Exception a.name when … when … end 我是否正确理解三重相等?

在Ruby / Rails中PHP的print_r是否相同?

在PHP中,您可以: print_r($var)或vardump($var) 它打印有关变量的“人类可读”信息。 Ruby / Rails中是否有等效的函数/帮助器?

Rails 2到Rails 3:使用link_to而不是link_to_remote(包括远程和更新)

我敢肯定,这是一个快速简单的答案。 我正在将Rails项目从版本2升级到版本3,并根据Rails 3更新用link_to替换link_to_remote的加载。 即使是这样简单的事情: :get_time}, :remote=>true, :update=>’current_time’ %> 似乎没有用。 请求(使用get方法)正常,渲染的html是: Check Time Routes.rb条目: get “monitoring/get_time” 正如我所说,我确信这对我来说是一个非常明显的问题!

在Rails中联系Form Mailer 4

我正在尝试在Rails 4中构建一个联系表单,其中表单采用名称,电子邮件和正文,并将其发送到我的电子邮件地址。 点击“提交”后,该应用会正确地重定向回联系人页面,但似乎没有电子邮件发送。 的routes.rb match ‘/send_mail’, to: ‘contact#send_mail’, via: ‘post’ contact_email.html.erb true %> true %> You have received the following email from contact_controller.rb def send_mail name = params[:name] email = params[:email] body = params[:comments] ContactMailer.contact_email(name, email, body).deliver redirect_to contact_path, notice: ‘Message sent’ end contact_mailer.rb class ContactMailer < ActionMailer::Base default to: # my email address def […]