Tag: ruby on rails 3.2

ruby on rails:收集选择的单选按钮

我有一个集合选择: 这种方法的单选按钮是什么? 谢谢

Rails路由:GET没有param:id

我正在开发基于rails的REST api。 要使用这个API,你必须登录。关于这一点,我想在我的用户控制器中创建一个方法,它将返回登录用户信息的json。 所以,我不需要在URL中传递:id 。 我只想打电话给http://domain.com/api/users/me 所以我尝试了这个: namespace :api, defaults: { format: ‘json’ } do scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do resources :tokens, :only => [:create, :destroy] resources :users, :only => [:index, :update] do # I tried this match ‘me’, :via => :get # => api_user_me GET /api/users/:user_id/me(.:format) api/v1/users#me {:format=>”json”} # Then […]

Rails如何使用image_tag列出文件夹中的所有图像?

我试图将所有图像放在’app / assets / images / slide’文件夹中并将它们与标签放在一起(按顺序)。 所以,它看起来像这样: 我怎么能得到这个? (我使用Rails 3.2.9) 这是我试过的代码(感谢Khaled)。 但它输出所有图像路径的纯文本列表。 我需要图像来显示: @images = Dir.glob(“app/assets/images/slide/*.jpg”) @images.each do |image| image_tag image.gsub(“app/assets/images/”, “”) end

ruby on rails在特定列名后添加一列

我尝试在表中的特定列之后向表中添加一列。 这是我做的: rails generate migration add_reaction_id_to_patient_allergies reaction_id: integer :after => ‘patient_id’ 这是我的迁移文件的样子: class AddReactionIdToPatientAllergies < ActiveRecord::Migration def change add_column :patient_allergies, :reaction_id, :string add_column :patient_allergies, :integer, :string add_column :patient_allergies, :, :after add_column :patient_allergies, :=, :string end end 我不认为命令进展顺利。 我在上面的文件中看到了’=’。 我不认为应该在那里。 有人能告诉我,如果我错过了什么? 如果是这样,我该如何撤消上述内容?

Rails控制台默认环境

在我的开发机器上: $ bundle exec rails console Loading development environment (Rails 3.2.3) 1.9.3p194 :001 > Rails.env => “development” 这是预料之中的。 到现在为止还挺好。 然而在我的生产服务器上(我使用Capistrano部署),我得到了完全相同的结果: $ bundle exec rails console Loading development environment (Rails 3.2.3) 1.9.3p194 :001 > Rails.env => “development” 在任何一台机器上,我都可以这样做: $ bundle exec rails console production Loading development environment (Rails 3.2.3) 1.9.3p194 :001 > Rails.env => “production” 我的问题是:在生产服务器上,不应该bundle […]

Rails check_box_tag如何在ajaxily检查时传递值

在我的Task模型的索引页面上,我想显示一个对应于我的Task数据库表中的boolean字段“complete”的每一行的复选框。 目前我的代码进入方法“完成”,但它不包含用户刚刚执行的复选框的值(即,如果他们只是选中了框,则它不会传递给我的“完整”方法)。 我如何传递用户刚刚执行的值 – 是选中还是未选中? /views/tasks/index.html.erb {:remote => true, :url => url_for( :action => ‘complete’, :id => task.id, :complete => task.complete ), :method => :put}, :class => ‘input-large’ %> 器/控制器/ tasks_controller#完整 # PUT /complete/1 def complete @task = Task.find(params[:id]) p “inside complete” p “complete = #{params[:complete]}” @task.complete = if @task.update_attributes(params[:task]) p “inside update” render :text […]

ruby bundle install require:没有这样的文件加载错误

我通过捆绑安装从我通过git克隆的应用程序安装gem遇到了麻烦。 以下是bundle install的输出结果: bundle install /usr/lib/ruby/vendor_ruby/bundler/rubygems_ext.rb:8:in `require’: no such file to load — rubygems (LoadError) from /usr/lib/ruby/vendor_ruby/bundler/rubygems_ext.rb:8 from /usr/lib/ruby/vendor_ruby/bundler.rb:11:in `require’ from /usr/lib/ruby/vendor_ruby/bundler.rb:11 from /usr/bin/bundle:4:in `require’ from /usr/bin/bundle:4 我读了谷歌和其他stackoverflow问题,但上面指出的文件是在ruby文件夹中,所以它不应该与应用程序有关(理论上这意味着我将无法捆绑任何应用程序的安装)。 任何方式如何解决这个问题? 任何帮助将深表感谢!

将暂存环境添加到工作流程

我目前有两个工作环境:本地development和Heroku production 。 我想在Heroku上添加一个staging环境,以便在将应用程序推送给用户之前看到一切都按预期进行。 优选地, staging环境应具有与production环境完全相同的设置和数据。 完成上述步骤需要哪些步骤?

为什么我不能使用重载方法在define_method中调用super?

当我运行下面的代码时,它会引发错误: 不支持从define_method()定义的方法传递super的隐式参数。 明确指定所有参数。 (RuntimeError)。 我不确定是什么问题。 class Result def total(*scores) percentage_calculation(*scores) end private def percentage_calculation(*scores) puts “Calculation for #{scores.inspect}” scores.inject {|sum, n| sum + n } * (100.0/80.0) end end def mem_result(obj, method) anon = class << obj; self; end anon.class_eval do mem ||= {} define_method(method) do |*args| if mem.has_key?(args) mem[args] else mem[args] = super end […]

rake assets:尝试连接数据库的预编译

我正在尝试调试为什么我的应用程序在运行rake assets:precompile –trace时尝试连接到我的数据库rake assets:precompile –trace 。 我可能在堆栈跟踪中遗漏了什么……有人看到了相关的线路吗? DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in ActionController::Base instead. (called from at /Users/Kyle/Desktop/skateparks-web/config/application.rb:4) ** Invoke assets:precompile (first_time) ** Execute assets:precompile /Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /Users/Kyle/.rvm/gems/ruby-1.9.2-p290@skateparks/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets –trace DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no […]