我有一个属于个人资料模型的工作模型.配置文件has_many工作.我有一个嵌套的模型表单,用户可以在其中添加作业.表单已成功添加作业,但编辑/更新无效.相反,当我尝试编辑作业时,它会保留旧版本的作业,但也会添加新版本.它不会用新版本替换旧版本.我该如何解决?我很确定它与编辑/更新控制器有关.
编辑控制器:
def edit
@profile = current_user.profile
end
Run Code Online (Sandbox Code Playgroud)
更新控制器:
def update
#if current_user.profile.jobs.any?
@profile = current_user.profile.update_attributes(profile_params)
if current_user.profile.invalid?
@profile = current_user.profile
render :edit, :status => :unprocessable_entity
else
redirect_to profile_path(current_user.profile_name)
end
end
Run Code Online (Sandbox Code Playgroud)
问题是,更新控制器正在处理非嵌套信息,它不适用于嵌套作业.以下是强大的参数:
def profile_params
params.require(:profile).permit(:title,
:category, :description, :state, :zip_code, :rate,
jobs_attributes: [:firm, :position, :category, :description,
:begin, :end, :_destroy])
end
Run Code Online (Sandbox Code Playgroud)
这是配置文件模型:
class Profile < ActiveRecord::Base
belongs_to :user
has_many :jobs
accepts_nested_attributes_for :jobs , :reject_if => :all_blank, :allow_destroy => true
end
Run Code Online (Sandbox Code Playgroud)
此外,这是我的路线,如果这将有所帮助:
resources :profiles do
resources :jobs
end
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助.
编辑
以下是创建动作中的参数:
{"jobs_attributes"=>{"1383593195849"=>{"firm"=>"1st firm", …Run Code Online (Sandbox Code Playgroud) ruby-on-rails nested-forms nested-attributes ruby-on-rails-4 rails-activerecord
我有一个 ruby 应用程序,自由职业者可以在其中为雇主完成工作。工作完成后,自由职业者可以上传文件供雇主审查。我认为自由职业者应该能够上传 zip 文件,但我不希望自由职业者能够上传无效或损坏的 zip 文件。有什么办法可以阻止这种情况或检查文件是否有效。我很确定是否有方法或函数可以做到这一点,它会在 rubyzip 库中,但我已经浏览了他们的文档,但找不到我要找的东西。
我有一个带有单选按钮的简单表单,它从服务器中提取值并循环遍历它们以提供单选按钮:
<form ng-submit="createSubCategory(subcategory)">
<div ng-repeat="sub_category in event_sub_categories" >
<label class="item item-radio">
<input type="radio" ng-model="subcategory" ng-value="'{{sub_category}}'" >
<div class="radio-content">
<div class="item-content">
{{sub_category}}
</div>
<i class="radio-icon ion-checkmark"></i>
</div>
</label>
</div>
<div class="padding">
<button type="submit" class="button button-block button-positive">Continue</button>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
表格完美显示.但是,我按下的单选按钮似乎没有保存.这是createSubCategory方法:
$scope.createSubCategory = function(subcategory){
console.log(subcategory);
}
Run Code Online (Sandbox Code Playgroud)
日志正在显示undefined.填写表格后如何记录子类别?
angularjs angularjs-controller angular-ngmodel ng-submit angularjs-ng-model
我已经尝试过 Devise 的 github 上的代码。在我的应用程序控制器中,我有:
after_filter :store_location
def store_location
# store last url - this is needed for post-login redirect to whatever the user last visited.
if (request.fullpath != "/users/sign_in" &&
request.fullpath != "/users/sign_up" &&
request.fullpath != "/users/password" )
session[:previous_url] = request.fullpath
puts 'stores location'
end
end
def after_update_path_for(resource)
session[:previous_url] || dashboard_path
puts 'after update'
end
Run Code Online (Sandbox Code Playgroud)
当我检查我的服务器时,会出现 store_location 方法中的 puts 语句,但 after_update_path_for 中的 puts 语句没有出现。如何让 after_update_redirect 工作?
这是设计所说的,但它不起作用:
ruby model-view-controller ruby-on-rails devise ruby-on-rails-4
我正在使用thumbs_up gem创建一个投票系统.我正在使用PostgreSQL.当我跑:
rails generate thumbs_up
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
/usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thumbs_up-0.6.7/lib/generators/thumbs_up/thumbs_up_generator.rb:21:in `create_migration': wrong number of arguments (3 for 0) (ArgumentError)
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/railties-4.0.4/lib/rails/generators/migration.rb:65:in `migration_template'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thumbs_up-0.6.7/lib/generators/thumbs_up/thumbs_up_generator.rb:22:in `create_migration'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/railties-4.0.4/lib/rails/generators.rb:156:in `invoke'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/railties-4.0.4/lib/rails/commands/generate.rb:11:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `block in require'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:214:in `load_dependency'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:229:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/railties-4.0.4/lib/rails/commands.rb:48:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我刚从另一台计算机上克隆了我正在处理的存储库.当我尝试通过运行'rake db:migrate'进行数据库迁移时,我收到以下错误:
AbstractController::Helpers::MissingHelperError:
Missing helper file helpers//users/psmith/projects/clie/projectlion/app/helpers/application_helper.rb_helper.rb
Run Code Online (Sandbox Code Playgroud)
我已经在这里尝试了最常见的答案:Rails:AbstractController :: Helpers :: MissingHelperError - 缺少帮助文件application_helper.rb_helper.rb
它说要在终端中执行以下操作:
cd ~
mv projects projects1
mv projects1 projects
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
sudo ln -s Users users
Run Code Online (Sandbox Code Playgroud)
但这对我不起作用.我该怎么办?
更新:
这是我的堆栈跟踪:
ps-MacBook-Pro:projectlion psmith$ rake db:migrate
rake aborted!
AbstractController::Helpers::MissingHelperError: Missing helper file helpers//users/psmith/projects/clie/projectlion/app/helpers/application_helper.rb_helper.rb
/Users/psmith/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/abstract_controller/helpers.rb:154:in `rescue in block in modules_for_helpers'
/Users/psmith/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/abstract_controller/helpers.rb:151:in `block in modules_for_helpers'
/Users/psmith/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/abstract_controller/helpers.rb:147:in `map!'
/Users/psmith/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/abstract_controller/helpers.rb:147:in `modules_for_helpers'
/Users/psmith/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_controller/metal/helpers.rb:93:in `modules_for_helpers'
/Users/psmith/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/abstract_controller/helpers.rb:111:in `helper'
/Users/psmith/.rvm/gems/ruby-2.2.0/gems/actionpack-4.1.4/lib/action_controller/railties/helpers.rb:17:in `inherited'
/Users/psmith/projects/clie/projectlion/app/controllers/application_controller.rb:1:in `<top (required)>'
/Users/psmith/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:443:in `load'
/Users/psmith/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:443:in `block in load_file'
/Users/psmith/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:633:in `new_constants_in'
/Users/psmith/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:442:in `load_file'
/Users/psmith/.rvm/gems/ruby-2.2.0/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:342:in …Run Code Online (Sandbox Code Playgroud) 我让sublime text 2命令行工具正常工作。当我下载Sublime Text 3时,我无法使用命令行工具。我在这里尝试了所有答案:在macOS中从Terminal打开Sublime Text。当我输入:
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
Run Code Online (Sandbox Code Playgroud)
我回来了:
ln: /usr/local/bin/subl: File exists
Run Code Online (Sandbox Code Playgroud)
但不管我做什么我仍然会回来 -bash: subl: command not found
我有以下设置:
class TeamEnrollment < ApplicationRecord
belongs_to :team
has_many :term_enrollments, through: :team
end
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常。现在我需要将 has_many 行更改为如下所示:
has_many :term_enrollments,
-> {where("(term_enrollments.term_start_date <= ? AND term_enrollments.term_end_date >= ?) OR (term_enrollments.term_start_date >= ? AND term_enrollments.term_end_date > ?) OR (term_enrollments.term_start_date <= ? AND term_enrollments.term_end_date >= ?)", self.start_date, self.start_date, self.start_date, self.termination_date, self.termination_date, self.termination_date)}
, through: :team
Run Code Online (Sandbox Code Playgroud)
从上面的代码中,如果我尝试这样做,我会收到以下错误TeamEnrollment.first.term_enrollments:
undefined method `start_date' for #<TermEnrollment::ActiveRecord_Relation:0x007ff706550550>
Run Code Online (Sandbox Code Playgroud)
我已经where用上面的代码的第一个配置测试了该子句,它工作正常。只有在has_many子句中它才不起作用。我很确定这与在has_many through. 我试图参考 TeamEnrollment 的 start_date。我该怎么做呢?
activerecord ruby-on-rails has-many-through rails-activerecord ruby-on-rails-5
我无法让glyphicons与bootstrap 3和rails一起使用.我已经在互联网上找到了灵感,没有找到任何帮助.在我的bootstrap.css文件中,我有:
@font-face {
font-family: 'Glyphicons Halflings';
src: url('/assets/glyphicons-halflings-regular.eot');
src: url('/assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}
Run Code Online (Sandbox Code Playgroud)
在application.rb中,我有:
config.assets.enabled = true
config.assets.paths << "#{Rails.root}/app/assets/fonts"
config.assets.precompile += %w( .svg .eot .woff .ttf )
Run Code Online (Sandbox Code Playgroud)
我已经尝试过跑:
rake资产:预编译RAILS_ENV =开发
在application.js我有:
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require bootstrap
Run Code Online (Sandbox Code Playgroud)
在application.css我有:
*= require_self
*= require_tree .
*= require bootstrap
*/
Run Code Online (Sandbox Code Playgroud)
我的所有字体都存储在资源/字体中
我已经看过以下内容,但没有一个有效:
Bootstrap 3 + Rails 4 - 某些Glyphicons不工作
我怎样才能解决这个问题?
ruby-on-rails asset-pipeline twitter-bootstrap twitter-bootstrap-rails ruby-on-rails-4
我已经使用 twilio api 发送消息 3 年了,它运行得很好。从 ruby 2.6 升级到 ruby 3.1.3 后,Twilio 不再工作。我们使用的是 twilio-ruby 5.74.2。我们收到错误ArgumentError (wrong number of arguments (given 1, expected 0)):。我有以下代码:
def send_pin_through_twilio
client = Twilio::REST::Client.new
client.messages.create({
from: ENV["twilio_phone_number"],
to: self.phone_number,
body: "Hello from ...! Your one-time pin is #{self.one_time_pin}."
})
end
Run Code Online (Sandbox Code Playgroud)
我们得到以下错误:
2023-02-03T17:11:25.312087+00:00 app[web.2]: F, [2023-02-03T17:11:25.311995 #4] FATAL -- : [0d0b1732-1dbc-4170-a3d3-ba99bb7a676e]
2023-02-03T17:11:25.312089+00:00 app[web.2]: [0d0b1732-1dbc-4170-a3d3-ba99bb7a676e] ArgumentError (wrong number of arguments (given 1, expected 0)):
2023-02-03T17:11:25.312089+00:00 app[web.2]: [0d0b1732-1dbc-4170-a3d3-ba99bb7a676e]
2023-02-03T17:11:25.312090+00:00 app[web.2]: [0d0b1732-1dbc-4170-a3d3-ba99bb7a676e] app/models/user.rb:157:in `send_pin_through_twilio'
2023-02-03T17:11:25.312090+00:00 app[web.2]: [0d0b1732-1dbc-4170-a3d3-ba99bb7a676e] app/controllers/api/v3/users_controller.rb:127:in …Run Code Online (Sandbox Code Playgroud) ruby ×4
activerecord ×1
angularjs ×1
bash ×1
carrierwave ×1
devise ×1
nested-forms ×1
ng-submit ×1
postgresql ×1
ruby-2.2 ×1
ruby-3.1 ×1
rubygems ×1
rubyzip ×1
sublimetext ×1
sublimetext3 ×1
twilio ×1
twilio-api ×1
zip ×1