Tag: 的Ruby on 轨道

Ruby On Rails:访问控制器中的link_to参数

假设我在模型的索引视图中有两个按钮,用于创建模型的新实例。 我想将变量:number传递给我的控制器并在new函数中使用它,这样我可以根据按下的按钮稍微改变我的形状。 我如何访问:number控制器中的数字? “btn btn-custom1” , :number => 1 %> “btn btn-custom1”, :number => 2 %>

Rails SQL注入:这段代码有多脆弱?

我正在尝试理解SQL注入。 看起来人们可以变得非常有创意。 这让我想知道我正在制作的基于搜索的rails webapp。 假设我只是将用户输入的信息直接输入到我的SQL查询的“where”语句中。 允许这样做可以对我的数据库造成多大的伤害? def self.search(search) if search includes(:hobbies, :addresses).where(search) else self.all end 所以基本上,无论用户在主页上的搜索栏中输入什么,都可以直接进入’where’语句。 有效“搜索”的一个例子是: “hobby LIKE ? OR (gender LIKE ? AND hobby LIKE ?)”, “golf”, “male”, “polo” 是否仅限于“where”语句的上下文提供任何forms的辩护? 他们还能以某种方式执行删除或创建操作吗? 编辑: 当我查看本教程时,我没有看到一种直接的方法来执行where子句中的删除或创建操作。 如果我的数据库中没有我不愿意从有效的搜索结果中显示的信息,并且没有用户帐户或管理员权限这样的东西,那么这里真正的危险是什么?

rails 2中的page.replace_html方法

这是我在客户端/订单控制器中的代码。 render :update do |page| page.replace_html “example_check” ,:partial=>’customer/orders/pending_orders’,:object=> “Your Message Has Been Sent ” end 在customer / orders / pending_orders.html.erb中 replace here 我想在另一个名为’customer/orders/pending_orders’控制器视图文件中替换”Your Message Has Been Sent “消息。 对于同一个控制器,更换工作正常。任何解决方案?

无法将nil转换为确切的数字

我希望用户能够评论其他人的微博,但我不断收到以下错误:无法将nil转换为确切的数字 它来自下面的View / comments / _form文件中的时间戳。 出于某种原因,@ comment.created_at以零返回 查看/评论/ _form :(在每个微博结束时调用此部分) Said ago.</span 用户模型: attr_accessible :name, :email, :password, :password_confirmation #is this secure with password there? attr_protected :admin #attr_protected necessary? has_many :microposts, dependent: :destroy has_many :comments, :through => :microposts, dependent: :destroy Micropost型号: attr_accessible :comment #basically the content of the post attr_protected :user_id has_many :comments, dependent: :destroy […]

使用ruby变量Rails find_by_sql

我正在尝试使用find_by_sql选择工作程序。 sql的where部分需要针对某些ruby代码进行测试: 我试过这个: <% Workorder.find_by_sql("SELECT * FROM workorders w JOIN empgroups e USING (workgroup_id) WHERE e.employee_id = ?, “).each do |workorder| %> 但是,它似乎没有预处理 谢谢您的帮助!

Belongs_to不同的字段名称

我inheritance了一个奇怪的表格布局: callbacks id, note, user admin id, name, password 在回调中,用户设置为admin的名称而不是实际的ID。 现在我需要能够调用callbacks.user并让rails用该名称查找admin,然后将其绑定到该记录。 我有一个名为users admin模型 我该怎么办呢?

循环内的Flash消息不会多次显示

每当自定义方法(进程!)在我的事务控制器中返回false或true时,我正在尝试显示一条消息。 但是,对于每个假,它只返回一次,对于每个真假只返回一次。 下面是控制器中的代码: def execute_all @transaction = Transaction.find(:all) #Execute all transactions @transaction.each do |t| if (t.process!) #flash.keep[:noticeTransaction] = ‘Transaction number: ‘ + t.id.to_s + ‘ executed Successfully!’ else flash.keep[:errorTransaction] = ‘Transaction cannot be executed -> Transaction Id: ‘ + t.id.to_s end end respond_to do |format| format.html { redirect_to transactions_url } format.json { head :no_content } […]

无法在Ruby上创建一个新的模型对象 – params是一个符号?

我得到一个奇怪的错误,我不明白。 似乎当我尝试创建一个新的模型对象时,有关params的一些东西正在被作为符号而我无法对它们做任何事情。 我得到的错误是: can’t convert Symbol into Integer 控制器动作是: def create user_info = :params[:user] if !user_info.value? “” if user_info[:password] == user_info[:password2] and user_info[:email] == user_info[:email2] user_info.delete(“password2”) user_info.delete(“email2”) @user = User.create!(user_info) @user = User.new(user_info) respond_to do |format| if @user.save format.html { redirect_to(@user, :notice => ‘User was successfully created.’) } else format.html { render :action => “new” […]

Ruby的UUID库列表

我正在寻找Ruby on Rails的UUIDgem列表,有人可以向我推荐一对夫妇,最好不要那么复杂,我不能轻易理解它们。

Rails:两个模型之间的多个Active Record关系

简短版本然后详细信息: 在我的应用程序中,用户有两个角色,员工和临床医生。 员工用户创建患者记录。 有时,工作人员用户将为他们自己的患者创建患者记录,并且有时工作人员用户将为具有另一个工作人员用户作为他们的医生的患者创建患者记录。 我的目的是在每个患者记录中包括创建记录的员工用户以及该患者的医生的员工用户。 我无法找出正确的活动记录关系来完成这项工作。 在我的患者表中,我有user_id来保存创建患者记录的员工用户的ID。 在我创建患者并执行Patient.last.user时,在控制台中,它返回创建记录的用户。 在我的病人表中,我也有doctor_id来保存该病人的医生的工作人员用户的身份。 在我创建患者并且做Patient.last.doctor的控制台中我收到此错误: ActiveRecord :: HasManyThroughAssociationNotFoundError:找不到关联:模型患者中的用户 我成功地保存了doctor_id,但我似乎无法按照我想要的方式取回医生的名字。 我是不是错了,或者这是不可能的,因为我正在使用的模式? 细节: class User < ApplicationRecord include Clearance::User include StaffUser include ClinicianUser validates :first_name, :last_name, :role, presence: true enum role: { staff: 0, clinician: 1 } 我有员工关注和临床医生的关注,生活在应用程序/模型/关注点下: clinician_user.rb require ‘active_support/concern’ module ClinicianUser extend ActiveSupport::Concern included do has_one :clinician_profile has_many :lists has_many […]