design - How to have conditional views in Rails? -


I saw a feature in an app that I want to be able to implement in the app has many resources - photos, articles etc. . Next to the photos and articles tab there were two buttons in the nav bar - Organization and Private When the organization clicks on the button, they click on the photo or article, they get a list of all the photos and articles of their organization members. If they click on the individual buttons and then they click on the photo or article, they only get a list of their personal photos and articles, leaving the resources of other members of their organization. So I wonder how this situation is kept between requests.

I think that in a way, a variable will be passed between the sequences and the controller and for a list of any special resource based on that variable. Or perhaps save the state in the session (though I think this should be done as a last resort) Another way is to use a decorator like draper , but I have to implement it I'm confused about the features. I am very grateful if someone tells me an article or a tutorial which tells the way to implement such a feature or just provides an overview of the steps.

To be clear, once again: Links are meant to point to various resources, but the index action of the respective controller on the basis of a parameter gives different results. Something like this:

  DRF index if parameters [: type] == 'organization' @ photo = organization. By fund_ (id: params [: organization] [: id]). Photos more @photos = User.find_by (id: params [: user] [: id]). Photos end end   

The question is how can I pass the type parameter - Path helpers have a hard code and for different parameters Along with different scenes or is there a better way?

This is related to my model:


  class users & lt; ActiveRecord :: Base is_to: Organization, inverse_of :: members have_im: photo, inward_off :: owner, foreign_key :: owner_id, dependent :: deleted ... end   
  class photos & lt; ActiveRecord :: Base is_to: owner, class_name: user, inver_service :: photo related_to: organization, inversion_of :: photo ... and   
  class organization & lt; ActiveRecord :: Base has has_many: member, class_name: user, inverse_of :: organization, dependent :: deleted has_many: photos, inverse_of :: organization, dependent :: deleted ... end    

Reloading the page with URL parameters

I have a similar problem And the couple had different ways to pass the parameters based on whatever you want there. I actually went with just passing them through the URL. If you have your url to ? Type = organization , you will get an additional key-value pair in your parameter, 'type' = & gt; 'Organization' and you can use it if you want to go to this URL through a link, you can simply link_to photos_path + "? Type = organization" . I have finished using Javascript because I wanted something other than a link, whatever your html element is, give it the attribute onclick = changeParam () and then that function in your javascript Define.

  function changeParam () {window.location. Search = "? Type = organization"}   

will automatically reload the same page with that parameter. If you want more than one, then whatever you have till now, it is amp; Param2 = value2 .

via AJAX

If you do not want to completely refresh the page, then you can also use AJAX to pass the parameter Are there. If you know how to use AJAX already, then just use the data option:

  $. Ajax ({type: "GET", url: "/ photos", data: {type: organization, Param2: value2}})   

In this case, Is sent in. If you want to know more about AJAX and how to use it, please let me know and I will update my answer with more details. This is quite confusing in the railways and there is no good documentation, so I will add what I add.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -