Tag: ruby on rails 3.2

Rails设计多态 – 使用Ajax渲染部分渲染

我已经从这个答案实现了多个模型的设计注册。 这个tuts从路径获取params user_type 。 我想用select user_type更改它。 因此,当我在select_tag上选择一个值时,将获得一个param user_type。 我有一些代码看起来像: 的routes.rb namespace :cp do devise_scope :user do match ‘/add_user’ => ‘registrations#new’ match ‘/select/admin’ => ‘registrations#selectuser’, :user => { :usertype => ‘admin’ } match ‘/select/player’ => ‘registrations#selectuser’, :user => { :usertype => ‘player’ } end end registrations_controller.rb def selectuser respond_to do |format| format.js end end new.html.erb Add […]

收集铁路3中所有路线的第一段

我正在尝试实现路由,其中​​第一个段是配置文件的别名或id: resources :profiles, :path => ” do … end 我需要validation其他(更高)路由的第一段尚未采用别名。 我现在拥有的是: validates :alias, :exclusion => {:in => Rails.application.routes.routes.map{|r| r.path.spec.to_s.split(‘(‘).first.split(‘/’).second}.compact.uniq }, …. 在开发过程中一切都很好。 在生产中Rails.application.routes.routes.map…返回空数组。 但是只有在模型中validation,如果我把它放在视图中只是为了测试它返回所有路径的第一段数组按预期。 我做错了什么或者有更好的解决方案?

Rails 3.2 – collection_select在我的数组的第一个位置添加空条目

我有一个Ruby on Rails 3.2.13应用程序,我有一个collection_select语句。 collection_select语句位于fields_for语句中,我从collection_select中收集选定的id并使用它们填充另一个表。 我遇到的问题是collection_select语句在数组中添加一个null id条目,用于存储所选id的集合。 以下是我视图中的代码: 以下是选择两个选项后数组的外观示例: “media_topics_attributes”=>{“0″=>{“topic_id”=>[“”, “2”, “47”], “id”=>”1895”}} 我认为数组应该只有两个id,“2”和“47”。 null值导致更新嵌套属性时出现问题,因为该错误表明该值不能为空。 当显示存在相关行的行的编辑视图时,将按预期选择并在列表中突出显示collection_select中的正确记录。 如何更改不添加空条目的collection_select语句? 我不允许添加MediaTopic模型上的任何行,其中topic_id等于null。 我已经研究了好几天了。 我发现一个人有一个类似的问题但是这个问题的解决方案都没有解决问题。 任何帮助,将不胜感激。

保护Ruby On Rails 3.2教程

我正在关注Ruby on Rails教程 。 事情进展顺利,但我注意到Guard仅在保存一些文件(视图或控制器文件)后运行,但在保存其他文件(路由或spec文件)时不运行。 我已经把警卫连接到Spork,不确定这是否重要。 当我查看运行Guard / Spork的控制台窗口时,我在保存非运行测试后发现错误: Exception encountered: #<LoadError: no such file to load — /Users/Tyler/Development/FirstRails/sample_app/spec/routing 我不确定Guard文件的语法是什么,我只是复制了这个例子。 这是Guard文件: # A sample Guardfile # More info at https://github.com/guard/guard#readme guard ‘rspec’, :version => 2, :all_after_pass=>false, :cli => ‘–drb’ do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| “spec/lib/#{m[1]}_spec.rb” } watch(‘spec/spec_helper.rb’) { “spec” } # my edits watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do […]

Ruby on Rails用法语发送flash消息

使用法语在rails应用程序上工作,但是每当我在flash消息中包含重音时,它就会破坏站点。 例如 format.html {redirect_to @message.annonce, notice:”Votre message a été envoyé”} format.html {redirect_to @message.annonce, notice:”Votre email n’a pas pu être envoyer à cause d’une erreur.”} 我的config / application.rb看起来像这样 config.i18n.default_locale = :fr config.encoding = “utf-8” 人们怎么做到这一点?

Rails Gem与Rails Engines的模型关系

我只是在开发一个有很多引擎的Rails应用程序。 但是,我无法编辑引擎内部的关系。 为了解决这个问题,我想创建一个关系-Gem,它将包含在Application中并定义关系(参见: https : //stackoverflow.com/a/11835899/603126 )。 让我们假设,我有一个用户(命名空间和隔离)引擎和一个注释(命名空间和隔离)引擎。 我想要的是覆盖/扩展关系中的关系 – Gem将分享关系。 所以我添加了一个文件/app/models/comment.rb与这些行(到关系-Gem): class Comment < CommentEngine::Comment belongs_to :user end class User < UserEngine::User has_many :comments end 如果我运行我的rails应用程序,则不会建立关系。 我错过了什么? 怎么能实现这一目标? 非常感谢你提前

rails helper方法如何:attribute_changed? 在Rails 3.2.15中有效吗?

这是我需要的情况:如果用户的电子邮件已更改,则生成用户确认代码 我有型号: class User < ActiveRecord::Base … after_update :generate_confirm_code if :email_changed? … def generate_confirm_code self.confirmation_code = SecureRandom.urlsafe_base64.first(8) self.confirmed = false end def update_last_visit self.last_visit = Time.now.utc save end … end 还有一个方法:application_controller中的update_last_visit,它可以节省用户上次访问时间 class ApplicationController < ActionController::Base … def update_last_visit current_user.update_last_visit if current_user end … end 这是问题的开始:每次我重新加载页面我的确认码都会改变,即使我没有更改电子邮件。 似乎更新last_visit也会更改confirmation_code,但为什么?

迁移错误:Gem:Module的未定义方法`cache’

通过rails app进行迁移时出现此错误 Gem:Module的未定义方法`cache’ 我正在使用 Rails 3.2.9 Ruby 1.8.7 Ubuntu 12.04 rake db:migrate –trace /home/rajendran/.rvm/gems/ruby-1.8.7-p374/gems/extlib-0.9.15/lib/extlib/object.rb:138: warning: method redefined; discarding old try_dup /home/rajendran/.rvm/gems/ruby-1.8.7-p374/gems/extlib-0.9.15/lib/extlib/symbol.rb:3: warning: method redefined; discarding old try_dup /home/rajendran/.rvm/gems/ruby-1.8.7-p374/gems/extlib-0.9.15/lib/extlib/time.rb:41: warning: method redefined; discarding old to_datetime /home/rajendran/.rvm/gems/ruby-1.8.7-p374/gems/extlib-0.9.15/lib/extlib/boolean.rb:2: warning: method redefined; discarding old try_dup /home/rajendran/.rvm/gems/ruby-1.8.7-p374/gems/extlib-0.9.15/lib/extlib/boolean.rb:8: warning: method redefined; discarding old try_dup /home/rajendran/.rvm/gems/ruby-1.8.7-p374/gems/extlib-0.9.15/lib/extlib/module.rb:14: warning: method redefined; discarding old try_dup […]

Rails 4 ckeditor文件上传

我在我的rails projec中使用了ckeditor,我的图像上传有问题。 我不想要ckeditor所拥有的一切,我为它写了一些简单的config.js: CKEDITOR.editorConfig = (config) -> config.language = ‘pl’ config.toolbar_Pure = [ ‘/’, { name: ‘basicstyles’, items: [ ‘Bold’,’Italic’,’Underline’,’Strike’,’Subscript’,’Superscript’,’-‘,’RemoveFormat’ ] }, { name: ‘paragraph’, items: [ ‘NumberedList’,’BulletedList’,’-‘,’Outdent’,’Indent’,’-‘,’Blockquote’,’-‘,’JustifyLeft’,’JustifyCenter’,’JustifyRight’,’JustifyBlock’,’-‘,’BidiLtr’,’BidiRtl’ ] }, { name: ‘links’, items: [ ‘Link’,’Unlink’ ] }, ‘/’, { name: ‘styles’, items: [ ‘Styles’,’Format’,’Font’,’FontSize’ ] }, { name: ‘colors’, items: [ ‘TextColor’,’BGColor’ ] }, […]

Active Admin NoMethodError错误

我在我的rails应用程序上设置了活动管理员。 我运行生成器来创建用户资源但是当我点击管理仪表板上的用户链接时,我得到: NoMethodError in Admin/users#index Showing /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/app/views/active_admin/resource/index.html.arb where line #1 raised: undefined method `city_id_contains’ for # Extracted source (around line #1): 1: render renderer_for(:index) 我不知道是什么产生了这个或错误来自何处..任何想法? 谢谢! (如果您需要查看任何其他文件,请告诉我) 楷模: user.rb class User < ActiveRecord::Base rolify devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable attr_accessible :province_id, :city_id belongs_to :province belongs_to :city province.rb class Province < ActiveRecord::Base has_many […]