小编Amr*_*ana的帖子

Ruby on Rails中的Gem Vs插件与引擎

Ruby on Rails中Gem包,插件和引擎有什么区别?

我认为我们在Rails3.2之前使用插件,在rails3.2发布之后我们使用gem包作为插件但是我们如何在ROR中使用引擎?

ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 ruby-on-rails-4

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

Rails4对find_or_initialize_by方法的弃用警告

我从3.2升级到Rails4.我有以下查询:

progress = Progress.find_or_initialize_by_chore_id_and_period_and_account_id(chore.id, period[chore.frequency], chore.account_id)
Run Code Online (Sandbox Code Playgroud)

在运行测试时,我收到了弃用警告

DEPRECATION WARNING: This dynamic method is deprecated. Please use e.g. Post.find_or_initialize_by(name: 'foo') instead. (called from bump_progress at /Users/newimac/RailsApp/bank/app/models/child.rb:200)
Run Code Online (Sandbox Code Playgroud)

所以,我更新了我的查询如下:

progress = Progress.where('chore.id' => 'chore_id', 'period[chore.frequency]' => 'period', 'chore.account_id' => 'account_id').first_or_initialize
Run Code Online (Sandbox Code Playgroud)

但它不起作用.我的查询是否正确?

ruby-on-rails ruby-on-rails-4

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

Rails 4身份验证

哪个gem最适合在Rails 4中进行身份验证?我尝试使用设计,但我遇到了问题.

.rvm/gems/ruby-2.0.0-p0/gems/activemodel-4.0.0.beta1/lib/active_model/deprecated_mass_assignment_security.rb:14:in `attr_accessible': `attr_accessible` is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add `protected_attributes` to your Gemfile to use old one. (RuntimeError)
    from /home/leapfrog/projects/kathloc/app/models/user.rb:8:in `<class:User>'
    from /home/leapfrog/projects/kathloc/app/models/user.rb:1:in `<top (required)>'
    from /home/leapfrog/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:423:in `load'
    from /home/leapfrog/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:423:in `block in load_file'
    from /home/leapfrog/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:615:in `new_constants_in'
    from /home/leapfrog/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:422:in `load_file'
    from /home/leapfrog/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:323:in `require_or_load'
    from /home/leapfrog/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:462:in `load_missing_constant'
    from /home/leapfrog/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/dependencies.rb:183:in `const_missing'
    from /home/leapfrog/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:226:in `const_get'
    from /home/leapfrog/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:226:in `block in constantize'
    from /home/leapfrog/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:224:in `each'
    from /home/leapfrog/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:224:in `inject'
    from /home/leapfrog/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-4.0.0.beta1/lib/active_support/inflector/methods.rb:224:in `constantize'
    from …
Run Code Online (Sandbox Code Playgroud)

authentication ruby-on-rails ruby-on-rails-4

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

Rspec在Rails 4 beta中没有生成*_spec.rb文件

我已经安装了rspec-rails gem.当我跑步时,rails g model movie showtime_date:date showtime_time:time我想,我应该得到

invoke  active_record
      create    db/migrate/20130604010556_create_movies.rb
      create    app/models/movie.rb
      invoke    rspec
      create    spec/models/movie_spec.rb
Run Code Online (Sandbox Code Playgroud)

但是当我跑步时rails g model movie showtime_date:date showtime_time:time 我得到了

invoke  active_record
      create    db/migrate/xxxxxxxxxxx_create_movies.rb
      create    app/models/movie.rb
      invoke    test_unit
      create      test/models/movie_test.rb
      create      test/fixtures/movies.yml
Run Code Online (Sandbox Code Playgroud)

我的gem包有问题吗?我正在使用Rails4 beta.这个版本有错误还是其他什么?

我的应用程序的BDD是这样的 app/features/show_descripitons.feature

Feature: Showtime Descriptions
    As a movie goer
    I want to see accurate and concise showtimes
    So that I can find movies that fit my schedule

    @wip
    Scenario: Show minutes for times ending with 00
        Given a movie …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails cucumber rspec-rails ruby-on-rails-4

7
推荐指数
1
解决办法
1423
查看次数

Rails升级语法错误,意外'\n',期待=>(SyntaxError)

我有这个问题

has_many :unused_invitations, :class_name => 'Invitation', :foreign_key => 'inviter_id', :conditions => 'used = false'
Run Code Online (Sandbox Code Playgroud)

我使用的是rails 3.2.17,现在我正在升级到rails 4.0.4.我收到了这个错误

DEPRECATION WARNING: The following options in your User.has_many :unused_invitations declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:

    has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'

should be rewritten as the following:

    has_many :spam_comments, -> { where spam: true }, class_name: 'Comment'
Run Code Online (Sandbox Code Playgroud)

我通过修改查询来解决它

has_many :used_invitations, class_name: 'Invitation', foreign_key: 'inviter_id', -> { where used: false}
Run Code Online (Sandbox Code Playgroud)

但我仍然得到语法错误

syntax error, …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails-4 ruby-2.1

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

如何在bitbucket中更改提交的用户名?

如何在bitbucket帐户中更改提交用户名?要改变git,我使用了这个命令

 git filter-branch -f --env-filter " GIT_AUTHOR_NAME='newUser' GIT_AUTHOR_EMAIL='newuser@email.com' " HEAD
Run Code Online (Sandbox Code Playgroud)

它只更改本地计算机中的用户名,但不会更改我的bitbucket帐户中的用户名.如何在bitbucket中更改提交的用户名?

git git-svn bitbucket bitbucket-api

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

如何撤消rm -rf?

我们如何撤消rm -rf命令?例如,我有Application文件夹.而我已将其删除

rm -rf Application
Run Code Online (Sandbox Code Playgroud)

但这是我的错误,并希望恢复或想要该应用程序文件夹.但它不在垃圾箱文件夹中.我现在应该怎么做 ?是否有任何撤消rm -rf的命令.

linux macos linux-kernel linux-mint ubuntu-12.04

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

Jquery更改事件在coffeescript中不起作用

嘿家伙我刚刚尝试在coffeescript中实现我的更改事件,但它不起作用.有没有人帮我

$('#subscription_id").on "change", -> 
console.log "Hello"
outputs = $(this).val()

if outputs
 $('#subscription_id').prop "disable", "false"
else
 $('##subscription_id').prop "disable", "true"
Run Code Online (Sandbox Code Playgroud)

jquery ruby-on-rails jquery-plugins coffeescript

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

::的ActiveSupport HashWithIndifferentAccess

我的控制器是这样的

class FriendController < ApplicationController
  def friend_list
    @user = User.new
  end

  def be_mine_friend
    @user = params[:user]
    if @user.save?
        redirect_to friend_mine_friend_url
        flash[:notice] = "#{@user[:name]} have been added to my friend list"
    else
        redirect_to friend_friend_list_path
    end     
  end

  def mine_friend
    @title = "Details list of Mine Friend"
    @friend = @user.paginate(page: params[:page], per_page: 10)
    respond_to do |format|
      format.html 
      format.json { render json: @friend }
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

查看friend_list的页面

    <div class="container">
        <%= notice %>
        <%#= errors %>
        <%= form_for(@user, url: friend_be_mine_frien_path) do |user| %>
            <%= …
Run Code Online (Sandbox Code Playgroud)

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

0
推荐指数
1
解决办法
1391
查看次数

为Same应用程序运行许多Rails服务器

是否可以在不同的端口运行相同的项目或应用程序?假设,我有项目/应用程序博客,我想在两个不同的端口立即在这个项目中运行.当我运行服务器即rails server,然后它运行在端口3000.再次,在下一个终端点击,我尝试相同的项目,但在不同的端口,即rails server -p 3001,但它不运行?

有没有其他方法可以在localhost服务器上的不同端口中以不同的方式运行相同的项目?

port ruby-on-rails localhost webrick ruby-on-rails-4

0
推荐指数
1
解决办法
1448
查看次数

Ruby数组转换

我有一串数字:

s = "12345678910"
Run Code Online (Sandbox Code Playgroud)

正如您所看到的那样,数字1到10按递增顺序列出.我想将它转换为这些数字的数组:

a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

ruby arrays string

0
推荐指数
1
解决办法
93
查看次数