ruby-on-rails-4

How do I validate certain fields with rails devise on registration only

拈花ヽ惹草 提交于 2021-02-19 04:06:55
问题 I have a set of custom fields attached to a devise model called Entrant. I have two forms, one for registration form (three fields) and one which sits in the account area (12 fields). Most of the custom fields area required but only within the form the sits in the account area. How do I achieve this? I am using rails 4.2 and ruby 2.1 回答1: You can simply specify validations on actions, that is: validates :name, presence: true, on: :create # which won't validate presence of name on update

How do I validate certain fields with rails devise on registration only

让人想犯罪 __ 提交于 2021-02-19 04:04:31
问题 I have a set of custom fields attached to a devise model called Entrant. I have two forms, one for registration form (three fields) and one which sits in the account area (12 fields). Most of the custom fields area required but only within the form the sits in the account area. How do I achieve this? I am using rails 4.2 and ruby 2.1 回答1: You can simply specify validations on actions, that is: validates :name, presence: true, on: :create # which won't validate presence of name on update

How to align input and label from collection_check_boxes?

戏子无情 提交于 2021-02-18 01:57:00
问题 I am using collection_check_boxes and have problems with aligning checkbox and text. This is my code: <div class="col-md-4"> <%= f.collection_check_boxes :dog_ids, Dog.all, :id, :name %> </div> Form is displayed like this: [checkbox1] text1 [checkbox2] text2 [checkbox3] text3 I am trying to align input and label but didn't have success. I have seen these question but it don't work for me: Align checkboxes for f.collection_check_boxes with Simple_Form I want to accomplish this: [checkbox1]

Check if folder exist in s3 bucket

谁都会走 提交于 2021-02-16 13:16:12
问题 How can I check if some folder exists in my s3 bucket using Ruby on Rails? I’m using AWS:S3 official gem After initializing the global connection AWS::S3::Base.establish_connection!(:access_key_id => 'my_key_id', :secret_access_key => ‘my_secret’) I have bucket named: myfirstbucket With folder inside named: my_folder With file inside my_folder named: my_pic.jpg When I try to check if my_pic.jpg exist it work just fine s3object.exists? “/my_folder/my_pic.jpg” , “myfirstbucket” => True How can

Getting ActionController::RoutingError (No route matches [OPTIONS] “/users” when trying to POST data to RAils server with AngularJS

橙三吉。 提交于 2021-02-16 13:06:24
问题 Having issue when trying to POST data to Rails server from my AngularJS side. The server error: ActionController::RoutingError (No route matches [OPTIONS] "/users"): actionpack (4.1.9) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' actionpack (4.1.9) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' railties (4.1.9) lib/rails/rack/logger.rb:38:in `call_app' railties (4.1.9) lib/rails/rack/logger.rb:20:in `block in call' activesupport (4.1.9) lib/active_support

Rails js.erb not working

自闭症网瘾萝莉.ら 提交于 2021-02-11 08:42:53
问题 I'm submitting a form, with somewhat complex nesting to a Rails controller. The Javascript is tied to the submit button as below: $('#new_search').submit(function() { var valuesToSubmit = $(this).serializeArray(); $.ajax({ type: "POST", url: $(this).attr('action'), //sumbits it to the given url of the form data: valuesToSubmit, dataType: "POST" }) return false; // prevents normal behaviour }); The Rails controller handles this fine and the parameters are all where they should be. I'm then

Rails datetime_select with time zone

拟墨画扇 提交于 2021-02-10 22:20:32
问题 I am writing a simple calendar app and having troubles with time zones. For as many nice Date and Time helpers, action view and active record sure don't play nice with time zones. I have an appointment model with the appointment_time attribute which is a datetime. My current issue is editing appointment_time with datetime_select within a form tag. <%= datetime_select :appointment_time, @appt.appt_time,ampm: true %> def appt_time appointment_time.in_time_zone(time_zone) #this is the

Deploy error ruby on rails Don't know how to build task 'assets:precompile'?

送分小仙女□ 提交于 2021-02-10 14:24:05
问题 I try to run on Digitalocean cap production deploy but i got this this error 00:42 deploy:assets:precompile 01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile 01 rake aborted! 01 Don't know how to build task 'assets:precompile' (See the list of available tasks with rake -… 01 /home/deploy/RubyProject/shared/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in <top (requi… 01 /home/deploy/.rbenv/versions/2.6.6/bin/bundle:23:in load' 01 /home/deploy/.rbenv/versions/2.6.6/bin/bundle

Rails: How to prevent the deletion of records?

痴心易碎 提交于 2021-02-09 10:12:24
问题 I have a model Country and therefore a table countries. The countries table act as a collection of iso country and currency codes and should never reduce there content (after I have filled it with seed data). Because Country is a subclass of ActiveRecord::Base it inherits class methods like destroy, delete_all and so forth which deletes records. I'm looking for a solution to prevent the deletion of records at the model level . Ofc. I know that I can make use of the object oriented approach to

Rails testing - Fixtures for has_many associations

℡╲_俬逩灬. 提交于 2021-02-08 18:38:39
问题 I am new to unit testing and have a simple use case. There are 2 models: City , Resident . A City has_many Residents. I created 2 fixture yml files: cities.yml, residents.yml. residents.yml resident1: name: resident1 resident2: name: resident2 resident3: name: resident3 cities.yml city1: name: city1 residents: resident1, resident2, resident3 When I run a trivial test that should always pass, I get an error : Minitest::UnexpectedError: ActiveRecord::StatementInvalid: Mysql2::Error: Unknown