Tag: ruby on rails 3.1

任何人都可以推荐一个用于搜索的gem,它实际上允许我轻松地在轨道上的ruby中过滤我的结果吗?

在指向那个方向后我尝试思考狮身人面像,简单的过滤似乎是不可能的。 我已经用Google搜索了2天的问题并且似乎无法做到这令人震惊,因为这是在网站上搜索时常见的事情。 我只想在搜索表单中添加过滤选项,例如过滤一个或多个组合: 当用户点击浏览页面时,将返回所有网站用户,但每页显示20个结果 过滤选项 在:位置 谁是:性取向 年龄间:年龄范围 和位于:国家 我的搜索页面工作正常,因为我需要的是用户通过电子邮件,用户名或全名查找用户的1个文本字段。 我的浏览页面是一个不同的故事,因为我使用的是一个包含多个文本字段和一个或两个选择字段的表单。 例 有没有一个gem可以轻松地做到这一点并同时表现良好? 或者通过查找方法手动执行此操作是唯一的方法吗? 亲切的问候

如何在Rails 3中指定使用迁移添加的字段顺序?

如何指定我想在哪个字段中添加新列? (我不希望在时间戳之后在底部添加字段) add_column :users, :is_active, :boolean

对rails中的attr_accessor和attr_accessible感到困惑

这是一个简单的注册应用程序 schema.rb create_table “users”, :force => true do |t| t.string “email” t.string “password_hash” t.string “password_salt” t.datetime “created_at”, :null => false t.datetime “updated_at”, :null => false User.rb attr_accessible :email, :password, :password_confirmation attr_accessor :password before_save :encrypt_password validates_confirmation_of :password validates_presence_of :password, :on => :create validates_presence_of :email validates_uniqueness_of :email . . . 为什么在attr_accessible和attr_accessor中都使用密码? 当我删除attr_accessor:password时,在rails控制台中,我在执行时遇到错误: user = User.new user.password # […]

AdminController中的AbstractController :: DoubleRenderError

我正在进行狂欢商务,我正在尝试调整active_sale_controller中的几个动作。 我有一些条件,如果条件失败,我会重定向(后退),否则我将继续下一步。 我现在面临的问题是我在同一个动作中使用了redirected_to(:back)两次,并且在同一个动作中我还有一个redirected_to到另一个控制器,浏览器显示一个错误,表示 “Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do […]

尝试使用实例化对象调用函数时没有方法错误

我有一个模型令牌,有三个字段user_id,product_id和unique_token 。在控制器中,我实例化了一个@token对象,其中包含从表单中收集的user_id和product_id值 。然后我用该对象调用save_with_payment函数,在我想要生成的函数中随机字符串3次并保存在unique_token字段中 。问题是self.tokens.create!( unique_token: Digest::SHA1.hexdigest(“random string”) )给我没有方法错误undefined method tokens我在这里做错了什么?为了阐明我想要完成的任务,我希望能够检索与user_find或product_id相关联的生成的unique_tokens列表,如User.find(1).tokens或Product.find(1).tokens 。模型关联是User has_many Tokens Product has_many Tokens 。 注意:unique_token字段最初来自Token模型,user_id和product_id只是ref主键。非常感谢! def create @token=Token.new(params[:token]) if @token.save_with_payment redirect_to :controller => “products”, :action => “index” else redirect_to :action => “new” end end class Token “usd”,card:stripe_card_token,:description => “Charge for bucks”) #self.stripe_customer_token = customer.id 3.times do self.tokens.create!(unique_token: Digest::SHA1.hexdigest(“random string”)) end save! end […]

在rails上的ruby中一次更新多个属性

我有一个页面,用户可以在当前线程对话中查看消息列表。 他们可以使用删除链接删除每条消息(每个消息的每个循环内的链接): :delete, :confirm => “Are you sure?”, :title => message.body %> 这基本上将它们连接到我的messages_controller中的动作: def destroy @message = Message.find(params[:id]) @message.update_attribute(‘sender_status’, 1) if @message.sender_id == current_user.id @message.update_attribute(‘recipient_status’, 1) if @message.recipient_id == current_user.id @message.destroy if @message.sender_status == 1 && @message.recipient_status == 1 flash[:success] = “Message deleted” redirect_to :back end 我现在想要的是在所有消息之前的一个链接(所以我不会把它放在每个块中)。 此链接将被称为“全部删除”,而不是使用值1更新1属性,它将所有属性(sender / recipient_status)更新为1,这样用户就不必单击每个单独的消息删除链接。 我有点担心如何做到这一点。 我不使用复选框,而是删除链接,所以对于删除所有我宁愿使用链接。 请问任何机构能为我提供一个解决方案吗? 我真的很感激。 我以为我昨晚睡在上面,早上有个主意但仍然没有想到。 […]

Ruby on Rails协会

我正在尝试一个应该有效的简单关联。 我按照http://ruby.railstutorial.org/chapters/和第10章的教程进行了操作 我在这里写下了什么 模型/客户 class Customer < ActiveRecord::Base has_many :posts, dependent: :destroy attr_accessible :name, :email, :password, :password_confirmation has_secure_password 模型/后 class Post < ActiveRecord::Base belongs_to :customer attr_accessible :description, :post_finish_at, :post_how, :post_location 控制器/客户 class CustomersController < ApplicationController before_filter :signed_in_customer, only: [:edit, :update] before_filter :correct_customer, only: [:edit, :update] def index @customers = Customer.all end def show @customer = […]

Rails如何在2个日期之间创建每月的图表数据?

在我的模型中,我有: def self.chart_data(start, slut) if start.nil? start = 2.weeks.ago end if slut.nil? slut = Date.today end range = start.to_date..(slut.to_date + 1.day) if start.to_date.beginning_of_month.to_s != slut.to_date.beginning_of_month.to_s kliks = count( :group => ‘date(month)’, :conditions => { :created_at => range } ) # CREATE JSON DATA FOR EACH MONTH – PROBLEM HERE (range).map(&:beginning_of_month).uniq.map(&:to_s).each do |month| { created_at: month, […]

Link_to rails嵌套表单编辑

我刚刚按照以下教程进行了很好的工作。 http://www.communityguides.eu/articles/6 然而,有一件事他对我来说很难,那就是编辑。 我打电话给我的link_to编辑了 然后,它带我到一个错误的页面,不知道为什么。 NoMethodError in Comments#edit Showing /home/jean/rail/voyxe/app/views/comments/_form.html.erb where line #1 raised: undefined method `comment_path’ for #<#:0xb65924f8> Extracted source (around line #1): 1: 2: 3: 4: prohibited this comment from being saved: 现在这里是评论编辑中的表格 prohibited this comment from being saved: 这是控制器文章控制器显示 @article = Article.find(params[:id]) @comments = @article.comments.find(:all, :order => ‘created_at DESC’) 评论控制器编辑 def edit […]

rails3-jquery-autocomplete并编写自己的搜索查询

这是我的控制器,我使用自动完成gem 。 我收到此查询的错误: SELECT users.id, users.phone, first_name, last_name FROM “users” WHERE (LOWER(users.phone) ILIKE ‘77%’) ORDER BY users.phone ASC LIMIT 10): ActiveRecord::StatementInvalid (PGError: ERROR: function lower(integer) does not exist 我的控制器: class CarsController < ApplicationController autocomplete :user, :phone … end 我想问你,我怎样才能进行自己的db查询以进行自动完成搜索 – 我需要将错误抛给上面,我认为没有其他办法… 当我将我的应用程序部署到Heroku时,我收到了此错误。