Show results depending on association2019 Community Moderator ElectionNameError in CompetitorsController#indexmultiple joins in railsHow to prevent Rails 2.3.8 from checking all dependencies while loadingdynamic nested form always creates an extra blank entry - using formtastic_coocoonwhere does rails get the queries for nested objects?Cant get model working for submit and validation on the show pageHow do I not use current_user in the modelRails 3.2.9 accepts_nested_attributes_for confusionGroup by entire field value in Tire/ElasticSearchHow to validate request parameters in rails 4 like laravel 5?

Why is this plane circling around the Lucknow airport every day?

MTG: Can I kill an opponent in response to lethal activated abilities, and not take the damage?

Finding algorithms of QGIS commands?

Why would a jet engine that runs at temps excess of 2000°C burn when it crashes?

They call me Inspector Morse

Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?

Look through the portal of every day

"One can do his homework in the library"

infinitive telling the purpose

Is there a window switcher for GNOME that shows the actual window?

How do I express some one as a black person?

Accountant/ lawyer will not return my call

Space in array system equations

The bar has been raised

Latest web browser compatible with Windows 98

Should I take out a loan for a friend to invest on my behalf?

In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?

Solving "Resistance between two nodes on a grid" problem in Mathematica

Low budget alien movie about the Earth being cooked

How to create a hard link to an inode (ext4)?

Is it true that real estate prices mainly go up?

Why is Beresheet doing a only a one-way trip?

Grey hair or white hair

PTIJ: Why can't I eat anything?



Show results depending on association



2019 Community Moderator ElectionNameError in CompetitorsController#indexmultiple joins in railsHow to prevent Rails 2.3.8 from checking all dependencies while loadingdynamic nested form always creates an extra blank entry - using formtastic_coocoonwhere does rails get the queries for nested objects?Cant get model working for submit and validation on the show pageHow do I not use current_user in the modelRails 3.2.9 accepts_nested_attributes_for confusionGroup by entire field value in Tire/ElasticSearchHow to validate request parameters in rails 4 like laravel 5?










0















I am building a landlord mgt application. But I am having an issue - I only want to index requests where the house.id (association value) matches the current user.



Currently, I have got it to work depending if the user has created it. But I would like the landlord to see all requests that are related to their properties.



requests_controller.rb:



def index
unless current_user.estate_agent?
@requests = Request.where(user_id: current_user).search(params[:search])
else
@requests = Request.search(params[:search])
end
end


request.rb



class Request < ActiveRecord::Base
belongs_to :user
belongs_to :house

def self.search(search)
key = "%#search%"
if search
where('description LIKE ? OR title LIKE ?', key, key)
else
all
end
end
end


house.rb



class House < ActiveRecord::Base
belongs_to :user
belongs_to :tenant
has_many :requests
belongs_to :contract

mount_uploader :energy, EnergyUploader

validates_presence_of :house_title, :description, :doorno, :postcode, :price, :bedroom, :house_type

def full_house_name
"#doorno #house_title"
end

def self.search(search)
key = "%#search%"
if search
where('doorno LIKE ? OR house_title LIKE ? OR price LIKE ? OR postcode LIKE ? OR house_type LIKE ? OR bedroom LIKE ?', key, key, key, key, key, key)
else
all
end
end
end









share|improve this question
























  • can you show your model relationship

    – widjajayd
    Mar 6 at 16:46






  • 1





    Try not to do an unless with an else, as that's a double negative. Instead use an if and reverse the order of the blocks. You'll also want to indent your code properly as right now it's all jumbled and hard to read, structurally speaking.

    – tadman
    Mar 6 at 16:54












  • @widjajayd added both models, thanks

    – Kush
    Mar 6 at 16:54















0















I am building a landlord mgt application. But I am having an issue - I only want to index requests where the house.id (association value) matches the current user.



Currently, I have got it to work depending if the user has created it. But I would like the landlord to see all requests that are related to their properties.



requests_controller.rb:



def index
unless current_user.estate_agent?
@requests = Request.where(user_id: current_user).search(params[:search])
else
@requests = Request.search(params[:search])
end
end


request.rb



class Request < ActiveRecord::Base
belongs_to :user
belongs_to :house

def self.search(search)
key = "%#search%"
if search
where('description LIKE ? OR title LIKE ?', key, key)
else
all
end
end
end


house.rb



class House < ActiveRecord::Base
belongs_to :user
belongs_to :tenant
has_many :requests
belongs_to :contract

mount_uploader :energy, EnergyUploader

validates_presence_of :house_title, :description, :doorno, :postcode, :price, :bedroom, :house_type

def full_house_name
"#doorno #house_title"
end

def self.search(search)
key = "%#search%"
if search
where('doorno LIKE ? OR house_title LIKE ? OR price LIKE ? OR postcode LIKE ? OR house_type LIKE ? OR bedroom LIKE ?', key, key, key, key, key, key)
else
all
end
end
end









share|improve this question
























  • can you show your model relationship

    – widjajayd
    Mar 6 at 16:46






  • 1





    Try not to do an unless with an else, as that's a double negative. Instead use an if and reverse the order of the blocks. You'll also want to indent your code properly as right now it's all jumbled and hard to read, structurally speaking.

    – tadman
    Mar 6 at 16:54












  • @widjajayd added both models, thanks

    – Kush
    Mar 6 at 16:54













0












0








0


0






I am building a landlord mgt application. But I am having an issue - I only want to index requests where the house.id (association value) matches the current user.



Currently, I have got it to work depending if the user has created it. But I would like the landlord to see all requests that are related to their properties.



requests_controller.rb:



def index
unless current_user.estate_agent?
@requests = Request.where(user_id: current_user).search(params[:search])
else
@requests = Request.search(params[:search])
end
end


request.rb



class Request < ActiveRecord::Base
belongs_to :user
belongs_to :house

def self.search(search)
key = "%#search%"
if search
where('description LIKE ? OR title LIKE ?', key, key)
else
all
end
end
end


house.rb



class House < ActiveRecord::Base
belongs_to :user
belongs_to :tenant
has_many :requests
belongs_to :contract

mount_uploader :energy, EnergyUploader

validates_presence_of :house_title, :description, :doorno, :postcode, :price, :bedroom, :house_type

def full_house_name
"#doorno #house_title"
end

def self.search(search)
key = "%#search%"
if search
where('doorno LIKE ? OR house_title LIKE ? OR price LIKE ? OR postcode LIKE ? OR house_type LIKE ? OR bedroom LIKE ?', key, key, key, key, key, key)
else
all
end
end
end









share|improve this question
















I am building a landlord mgt application. But I am having an issue - I only want to index requests where the house.id (association value) matches the current user.



Currently, I have got it to work depending if the user has created it. But I would like the landlord to see all requests that are related to their properties.



requests_controller.rb:



def index
unless current_user.estate_agent?
@requests = Request.where(user_id: current_user).search(params[:search])
else
@requests = Request.search(params[:search])
end
end


request.rb



class Request < ActiveRecord::Base
belongs_to :user
belongs_to :house

def self.search(search)
key = "%#search%"
if search
where('description LIKE ? OR title LIKE ?', key, key)
else
all
end
end
end


house.rb



class House < ActiveRecord::Base
belongs_to :user
belongs_to :tenant
has_many :requests
belongs_to :contract

mount_uploader :energy, EnergyUploader

validates_presence_of :house_title, :description, :doorno, :postcode, :price, :bedroom, :house_type

def full_house_name
"#doorno #house_title"
end

def self.search(search)
key = "%#search%"
if search
where('doorno LIKE ? OR house_title LIKE ? OR price LIKE ? OR postcode LIKE ? OR house_type LIKE ? OR bedroom LIKE ?', key, key, key, key, key, key)
else
all
end
end
end






ruby-on-rails ruby sqlite






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 7:37









Vasilisa

2,97521120




2,97521120










asked Mar 6 at 16:42









KushKush

105




105












  • can you show your model relationship

    – widjajayd
    Mar 6 at 16:46






  • 1





    Try not to do an unless with an else, as that's a double negative. Instead use an if and reverse the order of the blocks. You'll also want to indent your code properly as right now it's all jumbled and hard to read, structurally speaking.

    – tadman
    Mar 6 at 16:54












  • @widjajayd added both models, thanks

    – Kush
    Mar 6 at 16:54

















  • can you show your model relationship

    – widjajayd
    Mar 6 at 16:46






  • 1





    Try not to do an unless with an else, as that's a double negative. Instead use an if and reverse the order of the blocks. You'll also want to indent your code properly as right now it's all jumbled and hard to read, structurally speaking.

    – tadman
    Mar 6 at 16:54












  • @widjajayd added both models, thanks

    – Kush
    Mar 6 at 16:54
















can you show your model relationship

– widjajayd
Mar 6 at 16:46





can you show your model relationship

– widjajayd
Mar 6 at 16:46




1




1





Try not to do an unless with an else, as that's a double negative. Instead use an if and reverse the order of the blocks. You'll also want to indent your code properly as right now it's all jumbled and hard to read, structurally speaking.

– tadman
Mar 6 at 16:54






Try not to do an unless with an else, as that's a double negative. Instead use an if and reverse the order of the blocks. You'll also want to indent your code properly as right now it's all jumbled and hard to read, structurally speaking.

– tadman
Mar 6 at 16:54














@widjajayd added both models, thanks

– Kush
Mar 6 at 16:54





@widjajayd added both models, thanks

– Kush
Mar 6 at 16:54












1 Answer
1






active

oldest

votes


















0














If I understood you correctly, you want to show all requests that were made by the user or made for his real-state.



The code below will create your initial filter, then you can call your search method over it.



Request.where(user_id: current_user.id).or(Request.where(house: user_id: current_user.id))





share|improve this answer























  • Thanks @merehghost. I tried this but get a undefined error on the (or) part

    – Kush
    yesterday










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55028140%2fshow-results-depending-on-association%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If I understood you correctly, you want to show all requests that were made by the user or made for his real-state.



The code below will create your initial filter, then you can call your search method over it.



Request.where(user_id: current_user.id).or(Request.where(house: user_id: current_user.id))





share|improve this answer























  • Thanks @merehghost. I tried this but get a undefined error on the (or) part

    – Kush
    yesterday















0














If I understood you correctly, you want to show all requests that were made by the user or made for his real-state.



The code below will create your initial filter, then you can call your search method over it.



Request.where(user_id: current_user.id).or(Request.where(house: user_id: current_user.id))





share|improve this answer























  • Thanks @merehghost. I tried this but get a undefined error on the (or) part

    – Kush
    yesterday













0












0








0







If I understood you correctly, you want to show all requests that were made by the user or made for his real-state.



The code below will create your initial filter, then you can call your search method over it.



Request.where(user_id: current_user.id).or(Request.where(house: user_id: current_user.id))





share|improve this answer













If I understood you correctly, you want to show all requests that were made by the user or made for his real-state.



The code below will create your initial filter, then you can call your search method over it.



Request.where(user_id: current_user.id).or(Request.where(house: user_id: current_user.id))






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 at 10:11









MereghostMereghost

61847




61847












  • Thanks @merehghost. I tried this but get a undefined error on the (or) part

    – Kush
    yesterday

















  • Thanks @merehghost. I tried this but get a undefined error on the (or) part

    – Kush
    yesterday
















Thanks @merehghost. I tried this but get a undefined error on the (or) part

– Kush
yesterday





Thanks @merehghost. I tried this but get a undefined error on the (or) part

– Kush
yesterday



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55028140%2fshow-results-depending-on-association%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived