Tag: ruby on rail

REST API:使用cookie和会话的自定义方法

我正在尝试使用REST API,所以我想从一个RoR APP1中获取APP2中的@current_user。 在APP1 /config/routes.rb中我有这个代码: resources :users do collection do get ‘current’ end end 在APP1 /controllers/application_controller.rb中我有这样的代码: before_filter :current_user def current_user if cookies[:remember_me] current_user = user_from_cookie else current_user = User.find_by_id(session[:current_user_id]) end unless !current_user.nil? default_current_user = User.find_by_id(1) end return @current_user = current_user.nil? ? default_current_user : current_user end 在APP1 /controllers/users_controller.rb我有这个代码: def index … end def show … end […]

rails 3 + devise:如果注册表有错误,如何防止其他字段中的数据被删除?

我的设计注册表中有一个自定义字段(referral_code)。 还有一个自定义注册控制器(所以我可以在注册后重定向到自定义“检查您的电子邮件”页面)。 一切正常,除非新用户在显示错误消息时出错(例如密码/确认不匹配),它也会删除推荐代码字段。 当另一个字段(密码或电子邮件)向用户发送错误消息时,如何保持“填写”有效数据(推荐代码)?

delayed_job:NoMethodError

这是我的小Rails3控制器: class HomeController < ApplicationController def index HomeController.delay.do_stuff end def self.do_stuff puts "Hello" end end 访问index ,作业将正确插入数据库中: — !ruby/struct:Delayed::PerformableMethod object: !ruby/object:Class HomeController method_name: :do_stuff 问题:当执行bundle exec rake jobs:work ,我得到: Class#do_stuff failed with NoMethodError: undefined method `do_stuff’ for # 尽管HomeController.do_stuff工作得很好。 任何的想法?

安装Ruby on Rails但是当我尝试运行Rails Sever时它不加载WEBr​​ick?

我今天在Mac上安装了Ruby on Rails以及Gems和MYsql。 我正在尝试按照lynda.com教程,我遇到了一堵砖墙。 当我尝试运行rails服务器时,由于某种原因它不会加载WEBr​​ick。 这是我得到的错误: /Library/Ruby/Gems/1.8/gems/railties-3.0.5/lib/rails/script_rails_loader.rb:11:警告:不安全的世界可写dir / usr / local在PATH中,模式040777 /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/runtime.rb:136:警告:不安全的世界可写dir / usr / local在PATH中,模式040777 /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle:dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2。 bundle,9):未加载库:libmysqlclient.18.dylib(LoadError) 参考自:/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle 原因:找不到图像 – / Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle 来自/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2.rb:7 来自/Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in`requirement’ 来自/Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in`requirement’ from /Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in`the each’ 来自/Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in`requirement’ 来自/Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in“each” 来自/Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in`requiren’ 来自/Library/Ruby/Gems/1.8/gems/bundler-1.0.10/lib/bundler.rb:120:in`requirement’ 来自/Users/nutanpatel/Sites/simple_cms/config/application.rb:7 来自/Library/Ruby/Gems/1.8/gems/railties-3.0.5/lib/rails/commands.rb:28:in`requiren’ 来自/Library/Ruby/Gems/1.8/gems/railties-3.0.5/lib/rails/commands.rb:28 来自/Library/Ruby/Gems/1.8/gems/railties-3.0.5/lib/rails/commands.rb:27:in“tap” 来自/Library/Ruby/Gems/1.8/gems/railties-3.0.5/lib/rails/commands.rb:27 来自script / rails:6:in`require’ 来自script / rails:6 关于我能做什么的任何想法? 请帮忙 – 我被卡住了! 我做了rails -v,我在3.0.5: rails -v /Library/Ruby/Gems/1.8/gems/railties-3.0.5/lib/rails/script_rails_loader.rb:11:警告:不安全的世界可写dir / usr […]

Rails可安装引擎在动态范围内

说我有这些路线: scope ‘(:locale)’, :locale => /en|de/ do mount Users::Engine => “users”, as: ‘users_engine’ end 并在引擎视图中: 我明白了 /en/users/users/new?locale=de 代替 /de/users/users/new 我已经包含在应用程序控制器中: def set_locale if params.include?(‘locale’) I18n.locale = params[:locale] Rails.application.routes.default_url_options[:locale] = I18n.locale end end 它在主应用程序中工作正常 我找到了一种方法来获得正确的url Users::Engine.routes.url_for controller: ‘users/users’, action: :new, only_path: true, locale: :de 但我认为应该有更好的方法,如果我在布局中制作更改区域设置链接怎么办? 我不知道这可能是哪个引擎 谢谢你。

登录后重定向到特定URL

在Devise 1.0中,Rails 2.3的库是否有办法在登录后重定向到特定的URL而不是root_url? 编辑:忘了提它是Devise 1.0

如何将Devise的Rails应用程序转换为SSO / CAS服务器?

我从上一个问题中意识到我一直在问错误的问题…我想将我的应用程序转换为CAS服务器,以便应用程序的管理员可以使用相同的身份validation机制登录我们为其开发的其他应用程序组织。 你以前做过这个吗? 是否有插件增加了Devise能够充当CAS服务器的能力? 为了将应用程序变成CAS服务器,我需要更改/添加什么?

Rails:完全被delayed_job困扰。 在任何地方都没有收到

我正在尝试使用collectiveidea的delayed_job在Rails 3应用程序中发送邮件。 如果我尝试定期发送邮件(.deliver)它工作正常,但一旦我切换到延迟工作,事情就会崩溃。 我在delayed_job mysql表中得到的标准错误是: {undefined方法`name’代表nil:NilClass …… 其中’name’是邮件程序视图中的第一个参数(@ contact.name)。 如果我再次使用delayed_job,这可以正常工作。 如果我删除视图中对@contact的所有引用,我会得到 {发送邮件所需的发件人(Return-Path,Sender或From) 简而言之,它似乎根本不理解任何论据。 以下所有相关代码 – 如果有人对此有任何建议,将非常感谢 CONTROLLER def sendmail @contact = Contact.new(params[:contact]) if @contact.save ContactMailer.delay.contact_mail(@contact) flash[:notice] = ‘Your message has been successfully sent’ redirect_to root_path else render :action => ‘index’ end end MAILER: class ContactMailer “my@email.address” def contact_mail(contact) @contact = contact mail(:to => ‘my@email.address’, :subject […]

是否适合在模型中重复数据以满足集合中使用demeter的规律?

这是一个人为的例子,我想列出一个人有朋友的国家的人口,下面是两个设置。 是否最好在模型中重复数据? 我被告知德米特法则很重要,例如你告诉狗走路,指挥他的腿走路是愚蠢的。 在我丰富的经验(noob)中,我发现当模型重复数据时,查询会更容易, People.where(:country => friend.country) ,以及存在链接关联的集合(已经存在到目前为止不可能): People.where(:city => { :county => { :region => { :country => friend.city.county.region.country }}}) (这真的有助于这个noob在这里理解这个概念如果你能想象出正确设计的LoD设置和语法,我真的希望我没有使用与Demeter法则无关的例子)我试过通过delegate应用LoD并被告知我仍然链接(我是),我能想到的唯一解决方案是重复可以通过关联访问的数据。 但我讨厌重复数据! 这是由于我们重新创建了推特后DHH的Rails tutuorial,他展示了创建关系与重复数据的关系。 重复数据是否适合使关联更少链接? 模型,重复数据 class Country < ActiveRecord::Base has_many :regions has_many :counties has_many :cities has_many :people end class Region < ActiveRecord::Base has_one :country has_many :counties has_many :cities has_many :people end class County […]

设置SCORM课程进度

我只是想知道,无论如何你可以在运行时在SCORM文件中设置课程进度吗? 我应该检查哪种方法?