小编Ale*_*lex的帖子

git - 从特定的分支拉

我已经克隆了一个git存储库到我的开发服务器,然后切换到开发分支,但现在我不能做一个git pull来更新分支.

如何更新服务器上的代码?

git

169
推荐指数
8
解决办法
35万
查看次数

rails - 查找多个数组之间的交叉点

我试图找到多个数组之间的交集值.

例如

code1 = [1,2,3]
code2 = [2,3,4]
code3 = [0,2,6]
Run Code Online (Sandbox Code Playgroud)

结果将是2

我知道在PHP中你可以用array_intersect做到这一点

我希望能够轻松添加额外的数组,所以我真的不想使用多个循环

有任何想法吗 ?

谢谢,亚历克斯

ruby arrays ruby-on-rails array-intersect

68
推荐指数
2
解决办法
3万
查看次数

rails 3 - link_to以销毁无法正常工作

我正在尝试创建一个销毁链接到我的用户控制器,我也在使用设计.

这是我的代码 -

视图

<%= link_to 'Delete User?', child, :confirm => "Are you sure you want to delete #{child.full_name}?", :method => :delete, :class => "user-additional", :style => "font-size:12px;font-weight:normal;" %>
Run Code Online (Sandbox Code Playgroud)

调节器

def destroy
 if @user = User.find(params[:id])
  @user.destroy
  respond_to do |format| 
    format.html { redirect_to account_index_path } 
    format.xml { head :ok } 
  end
 end
end
Run Code Online (Sandbox Code Playgroud)

路线

devise_for :users 
resources :users, :except => [:new]
Run Code Online (Sandbox Code Playgroud)

该链接转换为localhost:3000/users/10

单击此按钮将打开用户显示而不是删除它们

有任何想法吗 ?

ruby-on-rails ruby-on-rails-3

37
推荐指数
4
解决办法
5万
查看次数

活动管理员 - 页面上未显示Flash消息

我试图在重定向到页面后显示通知但它没有出现.

这是重定向 -

redirect_to :action => :index, :notice => "My redirect"
Run Code Online (Sandbox Code Playgroud)

您可以在网址中看到该消息,但似乎活动管理员中没有任何代码可以显示它.

任何想法如何在活动管理员内呈现它?

ruby-on-rails ruby-on-rails-3.1 activeadmin

18
推荐指数
1
解决办法
1万
查看次数

Rails 3.1 - 查找使用计数并选择为

我试图在rails中执行以下sql语句:

SELECT COUNT(downloads.title) AS total, downloads.title FROM `downloads` WHERE `downloads`.`member_id` = 60 Group by `downloads`.`title`
Run Code Online (Sandbox Code Playgroud)

我在这样的rails中写了这个:

Download.where(:member_id => id).select("COUNT(downloads.title) AS total, downloads.title").group(:title)
Run Code Online (Sandbox Code Playgroud)

如果我直接从sql服务器运行查询sql正确执行但如果我运行activerecord版本我只返回标题.

我认为这可能是因为attr_accessible,但这似乎没有什么区别.

有任何想法吗 ?

activerecord ruby-on-rails ruby-on-rails-3.1

9
推荐指数
1
解决办法
2万
查看次数

生产服务器上的Rails安全性

我正在将我的第一个rails应用程序放在互联网上,我已阅读有关安全性的rails指南并已实现了那里列出的要点,但有兴趣听到其他任何内容?

另外,我目前将我上传的内容存储在公共/文件中,这样可以吗?我注意到没有htaccess文件保护目录.

ruby security ruby-on-rails

6
推荐指数
1
解决办法
359
查看次数

Rails 3 - has_many通过嵌套表单

我正在尝试使用嵌套表单,但在保存时不断收到此错误 -

uninitialized constant User::Userplan
Run Code Online (Sandbox Code Playgroud)

这是我的型号代码 -

用户

class User < ActiveRecord::Base 
  has_many :userplans
  has_many :plans, :through => :userplans
  accepts_nested_attributes_for :userplans
Run Code Online (Sandbox Code Playgroud)

UserPlan

class UserPlan < ActiveRecord::Base
 belongs_to :plan
 belongs_to :user
Run Code Online (Sandbox Code Playgroud)

计划

class Plan < ActiveRecord::Base
 has_many :userplans
 has_many :users, :through => :userplans
Run Code Online (Sandbox Code Playgroud)

形成

<%= form_for(@user) do |f| %>
 <%= hidden_field_tag "user[userplans][plan_id]", 2 %>
 <%= f.text_field :first_name %></p>
Run Code Online (Sandbox Code Playgroud)

我知道使用hidden_​​field_tag是错误的,但我不确定更好的方法

谢谢你的帮助!

activerecord(3.0.3)lib/active_record/associations/association_proxy.rb:260:在raise_on_type_mismatch' activerecord (3.0.3) lib/active_record/associations/association_collection.rb:352:in块中替换'activerecord(3.0.3)lib/active_record/associations/association_collection.rb:352:each' activerecord (3.0.3) lib/active_record/associations/association_collection.rb:352:in替换'activerecord(3.0.3) lib/active_record/associations.rb:1524:在block in collection_accessor_methods' activerecord (3.0.3) lib/active_record/base.rb:1559:inattributes 中的块='activerecord(3.0.3)lib/active_record/base.rb:1555:in each' …

ruby-on-rails ruby-on-rails-3

6
推荐指数
1
解决办法
1355
查看次数

MongoDB mongoid自我引用关系

我是mongo/mongoid的新手,我正在尝试在我的网站表上设置自引用关系.

# sites model

has_many :child_sites, :class_name => 'Site'
belongs_to :parent, :class_name => 'Site'

#controller

@event = current_site.child_sites.build(params[:site])
Run Code Online (Sandbox Code Playgroud)

current_site是一个返回当前站点对象的函数.

我收到此错误 -

#的未定义方法`entries'

mongodb mongoid

6
推荐指数
1
解决办法
5155
查看次数

工厂女孩多个has_many通过

我需要创建一些由多个工厂组成的工厂

这是我的模特

Topic
  has_many :plan_topics
  has_many :plans, :through => :plan_topics

PlanTopic
  belongs_to :plan
  belongs_to :topic

Plan
  has_many :subscriptions
  has_many :members, :through => :subscriptions
  has_many :plan_topics
  has_many :topics, :through => :plan_topics

Subscription
  belongs_to :member
  belongs_to :plan

Member
  has_many :subscriptions
  has_many :plans, :through => :subscriptions
Run Code Online (Sandbox Code Playgroud)

这就是我所拥有的

Factory.define :topic do |topic|
  topic.name "Operations"
end

Factory.define :plan do |plan|
  plan.title "A test Finance plan"
  plan.price "200"
end

Factory.define :plan_topic do |plan_topic|
  plan_topic.topic {|topic| topic.association(:topic)}
  plan_topic.plan {|plan| plan.association(:plan)}
end
Run Code Online (Sandbox Code Playgroud)

我想做的是 - 工厂(:member_with_subscription)

Factory.define :member_with_subscription do …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails factory-bot

6
推荐指数
2
解决办法
3599
查看次数

ruby rails将params转换为int数组

我通过get发送数据,我需要将它放入一个int数组,用于find.这是我的代码:

@found = Array.new
  params['candidate'].each do |c|
  @found << c.to_i
  end
Run Code Online (Sandbox Code Playgroud)

我的网址看起来像这样

http://localhost:3000/export/candidate?candidate[]=3&candidate[]=4&commit=Export
Run Code Online (Sandbox Code Playgroud)

如果它有任何区别我将它用于此查找

@candidate = Candidate.find(:all, :conditions => ["candidates.id IN ?", @found]) 
Run Code Online (Sandbox Code Playgroud)

但是目前它没有把它放在一个真正的数组中因为我得到了这个错误

Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '4)' at line 1: SELECT * FROM `candidates` WHERE (candidates.id IN 4,2)
Run Code Online (Sandbox Code Playgroud)

数组周围缺少括号

谢谢,早上好!

亚历克斯

ruby arrays ruby-on-rails

5
推荐指数
1
解决办法
1万
查看次数