spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

How do I use || operator so destroy ccurs in either of 2 instances?


Try this way.

Create a method in your app/models/user.rb(User):

def
find_by_passive_or_active_relatioship(id)
  passive_relationships.where(id: id).first ||
active_relationships.where(id: id).first
end

then in your controller:

def destroy
  @relationship =
current_user.find_by_passive_or_active_relatioship(params[:id])
  if @relationship.try(:destroy)
    flash[:success] = "Relationship destroyed"
  else
    flash[:error] = 'Relationship can be destroyed
at the moment. Try again.'
  end
  redirect_to root_path
end

You can use, find_by method instead of where(id: id), depending on your Rails version.

find raises RecordNotFound exception if it doesn't find the resource, while where().first or find_by methods don't.


Categories : Ruby On Rails

Related to : How do I use || operator so destroy ccurs in either of 2 instances?
How to destroy a Fragment that is on Backstack?
Firstly if you are using the BackStack, it is not typical to need to specifically manually remove Fragments, which suggests you might want to have another think about your design. That said, to specifically manually remove a Fragment, Override onBackPressed in your Activity which is showing the Fragments, manually remove the Fragment there. To make it easy to determine which Fragment is currentl

Categories : Android
The right time to destroy an interstitial ad
It really depends on how you're handling the ad. If the reference to the ad is a member of a monobehaviour class, you could call ad.Destroy() on the script's OnDestroy. If it's a local variable inside some method, then you have to call ad.Destroy() before leaving the method.

Categories : Unity3d
How do I destroy a session by clicking a button?
Use session_unset() to destroy all registered variables in the session and if you want unset a specific variable like name use unset($_SESSION['name']) Do NOT unset the whole $_SESSION with unset($_SESSION) as this will disable the registering of session variables through the $_SESSION superglobal.

Categories : PHP
Create and Destroy Linked Server in Stored Procedure
One of these servers contains somewhat sensitive information, and we would rather not have this server linked to the other all the time. Rubbish. If you do care about security, you should have tighten the security once and be done with it, rather than choosing a worst possible solution for an imaginary problem. Having said that, there are alternatives to linked servers designed specificall

Categories : SQL
Converting && (logical and) operator into || (logical or) operator
Yes they are. The first one is simply checking if both of them are true, and the second one checks if either of them are false. Both of them still return true if both are true, and false if not.

Categories : C
Recently Add
Groups and Users has many oder has many through?
Rails format specifier differences
Capistrano can not create symlinks: file exist
Admin can't delete users. Ruby on Rails 3 - Michael Hartl
Don't show user name who create post
Using Wicked with Devise (2 step signup process)
RubyOnRails Rake test failures
Rails session start event handler
Why ActiveModel::ForbiddenAttributesError error?
How can i track the issue in production RAILS
Cannot install spree gem - ERROR: invalid gem: package is corrupt
Why are the nested resources for Devise authentication not working?
Rails Devise - how to open access to the site root
Rails: respond_with the same template for two methods
rails with postgresl database "role postgres does not exist"
Instance variable in Rails helper not set
Monkey patch rails 3.2 rake task
Rails_admin: Should I have admin_user or user with admin role to manage users and admin panel
undefined method `attachments' for nil:NilClass
Memory usage increase with Ruby 2.1 versus Ruby 2.0 or 1.9
Can a Rails app be deployed without using Heroku Toolbelt? If so, how?
Enable random access to collection with MongoDB
libmysqlclient-dev installation fails
undefined method `name' for nil:NilClass. Can't find @followed.name but @followed is set
Allowing an arbitrary domain and subdomain in session_store.rb
Pushmeup Gem - Can't send push notifications in Active Admin model
Rails console does not start
GitHub Import: Could not locate Gemfile
AWS::S3::PermanentRedirect in SongsController#index "The bucket you are attempting to access must be addressed using the specified endpoint"
automatically create ActiveRecord parent for association
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.