Tag: ruby on rail

Rails中脚手架和模型之间的区别

生成支架和在Rails中生成模型有什么区别? 做任何一个的优点/缺点是什么?

Rails :(设计)新用户有两种不同的方法吗?

我有一个Rails 3应用程序,使用Devise并启用了可registerable模块进行身份validation设置。 我希望让使用我们的外部注册表单注册的新用户使用现在正在发生的完整的Devise可registerable模块。 但是,我还希望admin用户能够直接创建新用户,绕过(我认为)Devise的可registerable模块。 通过可registerable禁用,我的标准UsersController可以像admin用户一样工作,就像任何其他Rail支架一样。 但是,现在新用户无法自行注册。 启用registerable ,我的标准UsersController永远不会被调用新的用户操作(改为调用Devise::RegistrationsController ),我的CRUD操作似乎根本不起作用(我被转移到我的根页面而没有创建新用户)没有闪光信息)。 这是来自请求的日志: Started POST “/users” for 127.0.0.1 at 2010-12-20 11:49:31 -0500 Processing by Devise::RegistrationsController#create as HTML Parameters: {“utf8″=>”✓”, “authenticity_token”=>”18697r4syNNWHfMTkDCwcDYphjos+68rPFsaYKVjo8Y=”, “user”=>{“email”=>”test@test.com”, “password”=>”[FILTERED]”, “password_confirmation”=>”[FILTERED]”, “role”=>”manager”}, “commit”=>”Create User”} SQL (0.9ms) … User Load (0.6ms) SELECT “users”.* FROM “users” WHERE (“users”.”id” = 2) LIMIT 1 SQL (0.9ms) … Redirected to http://test-app.local/ […]

当改成Rails文件夹时,有rvm选择ruby和gemset吗?

对于我不同的Rails文件夹,我想让rvm在运行“bundle install”到执行’autotest’或rails console或server之类的任何东西时自动加载正确的gemset。 这可能吗? 目前我必须手动执行’rvm use’,这在我同时处理多个Rails项目时变得有点乏味。

什么。:格式意味着rake路线

我输入了rake路线,我得到了一堆这样的url – /articles/:id(.:format) 我的问题是 – .:format是什么意思? 从Rails指南路由文章中不清楚,并且在StackOverflow或google上没有其他有用的匹配.:format 。 有一个类似的格式是/:controller(/:action(/:id(.:format))) ,我也不明白。 谢谢 编辑跟进问题 – 如果我只想路由HTML页面。 最佳做法是在路由中指定类似。:html的内容或使用。:format并为format.html写一个respond_to块? 在后一种情况下,是否会忽略所有其他格式?

使用google_oauth2获取“错误:redirect_uri_mismatch”

url似乎正确(昨天上次更新): 文件也是: omn​​iauth.rb: provider :google_oauth2, ‘MY_CLIENT_ID.apps.googleusercontent.com’, ‘MY_CLIENT_SECRET’, :scope => ‘https://mail.google.com/mail/feed/atom/’ Error: redirect_uri_mismatch The redirect URI in the request: http://localhost:3000/auth/google_oauth2/callback did not match a registered redirect URI header.html.erb routes.rb中: match ‘/auth/:provider/callback’, to: ‘sessions#omniauth_create’ 但是我得到了这个: > Error: redirect_uri_mismatch The redirect URI in the request: > http://localhost:3000/auth/google_oauth2/callback did not match a > registered redirect URI (Twitter和Facebook OmniAuth工作正常) 不确定是什么问题。 […]

耙子流产了! 你已经激活了rake 10.0.2,但是你的Gemfile需要rake 0.9.2.2

我正在尝试“rake db:migrate”,它给了我这个错误。 Andy:AcademyAir Andy$ rake db:migrate /Users/Andy/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.2.2/lib/bundler/runtime.rb:197: warning: Insecure world writable dir /usr in PATH, mode 040777 rake aborted! You have already activated rake 10.0.2, but your Gemfile requires rake 0.9.2.2. Using bundle exec may solve this. /Users/Andy/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.2.2/lib/bundler/runtime.rb:31:in `block in setup’ /Users/Andy/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.2.2/lib/bundler/runtime.rb:17:in `setup’ /Users/Andy/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.2.2/lib/bundler.rb:116:in `setup’ /Users/Andy/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.2.2/lib/bundler/setup.rb:7:in `’ /Users/Andy/Desktop/AcademyAir/config/boot.rb:6:in `’ /Users/Andy/Desktop/AcademyAir/config/application.rb:1:in `’ /Users/Andy/Desktop/AcademyAir/Rakefile:5:in `’ (See full […]

Travis-CI上的Rails数据库设置

我正在尝试在Rails项目上使用Travis Continuous Integration。 文档说必须为SQLite3配置测试数据库如下: test: adapter: sqlite3 database: “:memory:” timeout: 500 但我想保留本地测试的默认配置。 是否可以保留我的本地设置和Travis要求?

在rake中销毁Rails 3对象?

我在这里遇到一个简单的问题。 我正在构建一个管理优惠券数据库的应用程序,每个优惠券都有一个到期日期。 我正在尝试建立一个rake任务,删除过期的优惠券。 rakefile中的相关代码如下所示: desc “Deletes expired offers from the database.” task :purge_expired => :environment do today = Date.today.to_s Offer.where(‘expires_on < ?', today).destroy end 然而,这失败,出现以下错误消息: rake aborted! wrong number of arguments (0 for 1) 我只是不确定为什么。 需要什么论据? 作为一个实验,我发现这很好: desc “Deletes expired offers from the database.” task :purge_expired => :environment do today = Date.today.to_s puts Offer.where(‘expires_on < […]

管理员更改用户的批准状态 – Rails + Devise + Cancancan

我按照此链接找出如何让管理员批准新用户。 我的User模型上有一个approved属性,它是一个布尔值。 2个问题 – 1)当我以管理员身份登录并通过link_to “Edit”, edit_user_path(user)转到编辑用户时link_to “Edit”, edit_user_path(user)更改已批准的用户 – 该URL用于正确的用户,但更新操作会尝试更新当前的管理员用户。 2)我更希望覆盖所需的当前密码,所以我在Registrations控制器中放置一个方法来执行此操作,但是会出现此错误: 错误:用户的unknown attribute ‘current_password’ for User. 所以它不会覆盖current_password ,也不会更新正确的非管理员用户 – 我哪里错了? class Ability include CanCan::Ability def initialize(user) current_user ||= User.new # guest user (not logged in) if current_user.admin == true can :manage, :all else can :manage, User, id: user.id end end end 路线 Rails.application.routes.draw do […]

未定义的局部变量或#User的方法`confirmed_at’

我正在使用Rails 3.这里可能有重复。 但它没有解决我的问题,也没有解决任何其他问题。 我的迁移如下 class AddConfirmableToDevise true end end 我确实devise :confirmable在User模型中添加了devise :confirmable 。 我的rake db:migrate没有输出。 我的注册页面给出了错误: undefined local variable or method ‘confirmed_at’ for #User 有人有线索吗?