Tag: ruby on rails 3

在config.rb中为scss文件创建scss变量

如何在Config.rb中为SCSS文件[COMPASS项目]定义SCSS变量 我的用例 在Config.rb文件中 a = true 在style.scss中我喜欢使用变量之类的 @if a == true{ background: #fff; } @else { background: #000; } 其中一个解决方案是http://worldhousefinder.com/?p=124141 但它对我不起作用。

使用sidekiq时Rails动作邮件程序中的动态域名

在我的要求中,单个项目有不同的域名。我想发送重置密码链接与用户请求重置密码的域名。为此我在application_controller.rb中完成了以下操作并且它运行良好。 before_filter :set_mailer_host def set_mailer_host ActionMailer::Base.default_url_options[:host] = request.host_with_port $url_host = request.host_with_port end 后来,我使用了sidekiq作为延迟邮件程序,并在整个应用程序中更新如下 Notifier.delay.password_reset(user.id) 由于邮件程序配置了sidekiq,它使用的是仅在配置中提供的默认域名,并且它没有使用application_controller.rb上的请求提供的动态域名 任何关于在sidekiq运行的邮件程序上获取动态域的建议都将非常感激。 Rails – 3.2.8 Ruby – 1.9.3 sidekiq – 2.13.1 谢谢!!!

升级到rails3后,after_find回调中断

素不相识的! 在一个在Rails 2.3.8中完美运行的应用程序中,我有以下类方法: def self.encode(*attr_names) encoder = Encoder.new(attr_names) before_save encoder after_save encoder after_find encoder define_method(:after_find) { } # defining here, since there’s only alias in the Encoder class itself end 此方法引用Encoder类。 就这个: class Encoder include Encodings def initialize(attrs_to_manage) # We’re passed a list of attributes that should be stored encoded in the database @attrs_to_manage = […]

更好的搜索查询两列forename和name

实际上我有来自MrJoshi的这个搜索查询这里是相关的问题: 搜索查询(名称或名称)和(名称forname)和(forname名称) def self.search(query) return where(‘FALSE’) if query.blank? conditions = [] search_columns = [ :forname, :name ] query.split(‘ ‘).each do |word| search_columns.each do |column| conditions << " lower(#{column}) LIKE lower(#{sanitize("%#{word}%")}) " end end conditions = conditions.join('OR') self.where(conditions) end 此搜索查询的问题在于它返回多条记录的方式。 例如,如果某人正在搜索John Smith此搜索查询将返回所有带有name Smith forename John记录和所有name Smith记录,尽管只有一个人与搜索查询完全匹配,因此name is Smith and forename is John所以我更改了代码一点点: def self.search(query) return where(‘FALSE’) […]

Rails试图将字符串转换为日期时间,但它没有保存到db

我正在尝试使用文本字段作为用户将日期作为日期进行编辑的地方。 通过这个例子,我正在努力,还没有生日。 我想要添加的生日是03/21/1986 。 这是控制器方法: # PUT /contacts/1/edit # actually updates the users data def update_user @userProfile = User.find(params[:id]) @userDetails = @userProfile.user_details respond_to do |format| if @userProfile.update_attributes(params[:user]) format.html { flash[:success] = “Information updated successfully” redirect_to(edit_profile_path) } else format.html { flash[:error] = resource.errors.full_messages render :edit } end end end 这是模型方法。 您可以看到我正在调用validation方法:birthday将其转换为日期。 一切似乎都有效,但没有任何东西保存到数据库,我没有错误。 # validate the birthday […]

nil的未定义方法:NilClass,相同的控制器动作工作正常吗?

我有一个ConversationsController有两个相同的动作: def index @conversations ||= current_user.mailbox.inbox.all @trash ||= current_user.mailbox.trash.all end def trashbin @conversations ||= current_user.mailbox.inbox.all @trash ||= current_user.mailbox.trash.all end 唯一的区别是视图中显示的信息。 索引页面显示数据就好了。 但是,对于出现在trashbin视图中的每个实例变量,我收到以下错误: undefined method ‘count’ for nil:NilClass 视图: 伯爵恰好是视图页面中使用的第一种方法。 除了一些纯文本之外,两个动作之间的视图几乎相同。 我很难过为什么我在一个动作上遇到错误。 我在索引页面上使用 ,它工作正常。 唯一的可能是路径文件出错。 我在使自定义垃圾箱路由工作时遇到了一些麻烦,所以我认为问题在于路径文件: resources :conversations do member do post :reply post :trash post :untrash end collection do get :trashbin, :action => ‘trashbin’ end […]

使用Rails的Ruby扩展时要考虑什么?

我想为Ruby创建一个C ++扩展(使用外部库,即stdlib和OpenCV),然后将其引入Rails项目。 有没有什么特别的东西可以使它与Rails兼容,或者更好的是,是否有一个Rails框架使得编写扩展(特别是对于C ++)更容易?

PostsController#中的ActiveRecord :: RecordNotFound显示单击链接

错误 ActiveRecord::RecordNotFound in PostsController#show Couldn’t find Post with id=morecommented Request Parameters: {“id”=>”morecommented”} 我在哪里做错了? postscontroller #show action def show @post = Post.find(params[:id]) … end morecommented.html.erb ‘/posts’, :action => ‘show’, :id => t.id %> 耙路线 post GET /posts/:id(.:format) {:action=>”show”, :controller=>”posts”} …. posts_morecommented /posts/morecommented(.:format) {:controller=>”posts”, :action=>”morecommented”} routes.rb中: resources :posts match “posts/:id/categ” => “posts#categ” match “posts/:id/tag_posts” => “posts#tag_posts” match […]

获取has_many:x,:through =>:y的问题在控制台中工作

创建新的Rails应用程序(终端) rails new hmt cd hmt 生成模型,脚手架,数据库架构等(终端) rails g model magazine name rails g model reader name rails g model subscription magazine:references reader:references 根据生成的DB模式(终端)创建表 rake db:migrate 检查表是否已创建好(终端) rails c (Rails控制台) Magazine.column_names Reader.column_names Subscription.column_names 在models /(magazine.rb)中指定关系 class Magazine :subscriptions end (reader.rb) class Reader :subscriptions end (subscription.rb) class Subscription < ActiveRecord::Base belongs_to :reader belongs_to :magazine end 添加一些数据(Rails控制台) […]

通过Form使用Rolify以及Devise和Cancan动态添加角色

我只是按照教程“ https://github.com/EppO/rolify/wiki/Tutorial ”非常好,工作正常。 但我的问题不能通过表单添加角色而不使用Rails控制台。 Role列连接到角色表(Rolify Roles) 这是我的角色.rb class Role <ActiveRecord :: Base has_and_belongs_to_many:users,:join_table =>:users_roles belongs_to:resource,:polymorphic => true User.rb class User <ActiveRecord :: Base belongs_to:account,:inverse_of =>:users validation:account,:presence => true rolify attr_accessible:role_ids #包括默认设计模块。 其他可用的是:#:确认,:可锁定,:超时和:omniauthable 设计:database_authenticatable,:registerable,:recoverable,:rememberable,:trackable,:validatable #为您的模型设置可访问(或受保护)属性 attr_accessible:email,:password,:password_confirmation,:remember_me,:role_ids #attr_accessible:title,:body has_many:auditinits 结束 任何帮助都很感激!!