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 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: The question is how can I pass the This is related to my model: 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 will automatically reload the same page with that parameter. If you want more than one, then whatever you have till now, it is 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: 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. 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.
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
type parameter - Path helpers have a hard code and for different parameters Along with different scenes or is there a better way?
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
? 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"}
amp; Param2 = value2 .
$. Ajax ({type: "GET", url: "/ photos", data: {type: organization, Param2: value2}})
Comments
Post a Comment