简体   繁体   中英

Refresh partial locally in Rails

I have a partial and a separate selection box.

I want to be able to reload the partial with different hash values every time the selection is changed.

I know there is no such entity 'partial' in the client, but is there an easy way to refresh the rendered html in the client?

Thank you

It sounds like what you need to do is make a partial for each selection option. So, if your select options are 'foo', 'bar' , and 'foobar' you would have three partials: _foo.html.erb , _bar.html.erb , and _foobar.html.erb . Then, you can define a helper (let's say render_selected_partial(option) where (option) takes in what the user selects. You can define the helper as follows:

def render_selected_partial(object)
  render: 'views/directory/#{object.attribute}'
end

This is very abstract since you haven't provided any concrete examples, and it is assuming that your select box options are types of a defined attribute of the model. I'm not sure what you mean by 'refresh the rendered html in the client' but that seems like an AJAX call that can be triggered when the user makes a selection, and then you can call the helper I defined in the .js file. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM