logo
down
shadow

rails 4 update record without using default update method


rails 4 update record without using default update method

By : Daniel
Date : November 14 2020, 04:51 PM
will help you I want to update a model record without using the default update method. I want to use my custom method to update it. I want to use custom method like , You should change the method from POST to patch:
code :
resources :promotions do
    collection {
      patch :update_record
    }
  end


Share : facebook icon twitter icon
Can Rails ActiveRecord #save method be used to update an existing record?

Can Rails ActiveRecord #save method be used to update an existing record?


By : ming_java
Date : March 29 2020, 07:55 AM
I wish this help you Yes. An ActiveRecord object in Rails retains its identity in the ID parameter. If the ID is set, Rails will know to update the record in the database with that ID.
save is, in fact, the primary way to create, update, or in any way save an object to the database. Other methods like update_attributes are just sugar that use save at their core.
Rails find_or_create method AND update record attributes

Rails find_or_create method AND update record attributes


By : Navneet Pathak
Date : March 29 2020, 07:55 AM
help you fix your problem Sounds like you want something that does a create_or_update_by,
which could be these two steps:
code :
my_app_class = ClassName.find_or_initialize_by_name(last_name, first_name).update_attributes
({
   :last_name => self.last_name,
   :first_name => self.first_name,
})
Rails after_save method trying to update record over and over

Rails after_save method trying to update record over and over


By : wuxiaoming
Date : March 29 2020, 07:55 AM
around this issue If you need to call process_pages only once after Creating a Page record and not after Updating a Page record then I would suggest to use after_create instead.
code :
class Page < ActiveRecord::Base
  require 'open-uri'

  after_create :process_pages

  def process_pages
    self.html = open(self.url).read
    self.save
  end 
end
Undefined method update when updating a record in Rails

Undefined method update when updating a record in Rails


By : user3658740
Date : March 29 2020, 07:55 AM
it fixes the issue It raises an error, because Country by given code was not found, then find_by returns nil, on which update method does not exist.
Instead of find_by executrun find_by! - you should get ActiveRecord::RecordNotFound error
code :
if @country
  @country.update ... 
end
Update method not updating record in rails 4

Update method not updating record in rails 4


By : Binoy Kumar
Date : March 29 2020, 07:55 AM
I hope this helps you . i have create a scaffold controller in which i can delete a record, update a record and create a new record. All methods working fine but update method not working. When i update any record then on submit it just show me flash notice that record updated successful but when i check my db nothing was change. Here below my update method in my controller.Kindly suggesst me what i have done wrong please. , It's because you didn't tell it to update. You should have:
Related Posts Related Posts :
  • In Ruby on Rails, After send_file method delete the file from server
  • An error occurred while installing nokogiri (1.6.6.2), and Bundler cannot continue
  • How to setup nested routing for a self referencing controller in Rails 4
  • middleman app it is possible to create a contact form?
  • How to refactor this piece of code
  • How can I know if a user has access to all or just some resources with Cancan?
  • How can I run a ruby class from rake file?
  • Send JSON data as post method from rails controller to a web service
  • How to test Controllers under different namespaces and why this test fails?
  • rspec expect condition OR condition
  • Page loads unnecessary queries Ruby On Rails
  • Why "bundle install" try to install outdated version of gems?
  • Rails - Customize model validation error messages but without a database
  • When to switch from cucumber to rspec in the BDD cycle for a login procedure
  • Multipart response for web service
  • How to hide Add new option in Rails Admin
  • Override CollectionProxy find method
  • Rails 4 simple_form has_many through check boxes not saving
  • ruby on rails authentication using devise gem
  • Rails iteration over arrays and hashes
  • Creating inline date_select dropdowns using simple_form and zurb foundation
  • NameError in SongsController#index uninitialized constant Song::FriendlyId
  • Rails how to improve if record exists?
  • omniauth custom request phase form
  • Rails 5 - Saving the absolute current url via a button to a cookie?
  • How can / should I override the `build` method for a my model?
  • Install Rails Failed on OSX 10.8.4
  • ruby on rails - undefined method valid?
  • Users Registration on POST
  • Rails application variables in carrierwave store_dir
  • How to customize simple_form for json nested hash
  • Couldn't find file 'jquery', Sprockets::FileNotFound in StaticPages#home error
  • How should I use the alias_method_chain for the build method?
  • how to create two custom registration forms in devise?
  • Rails 4 link_to Destroy not working in Getting Started tutorial
  • How does ruby on rails dynamically define `find_by_id`, `find_by_name` methods?
  • JBuilder dynamic keys for model attributes
  • `initialize': No such file or directory - getaddrinfo (Errno::ENOENT) when Rails new app
  • What is the Ruby equivalent of Node.js' socket.io?
  • Where rails store standard helpers?
  • how to check expected result matches any of give values in rspec?
  • Form submission to create multiple objects
  • Simple Twitter Login with Rails and Email confirmation
  • Where should helpful functions for my controller go in Rails?
  • Using session variable in the Model or the other way
  • Why can't I have ruby code and comments in Embedded Ruby?
  • Rails: How can I make an object available in all views?
  • Cannot enter simply form information into SQLite DB (Rails)
  • Rails - Retain form values on failed submission. Getting "First argument in form cannot contain nil or be empty&quo
  • How to handle STI and build related models automatically?
  • Suppress an error when saving a record in Rails
  • Rails AJAX reload the page. Why?
  • How to pass user attributes to action mailer
  • Custom Validator to Prevent an appointment from being scheduled too early in day?
  • Postgres Enable TCP/IP Connection
  • How do I avoid the circular argument reference warning in activesupport
  • Unable to push to heroku master because of rails/spring version error
  • deep nested routes in rails
  • Best approach to Users Profile Images in Rails App
  • RailsInstaller: Can I maintain the gem fold when re-installing a new version?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org