Hello,
I have a partial that I would like to allow users to either display or
not display a partial, by clicking a gif.
I want it so that when they click an "x", the partial is hidden, and
the "x" becomes a check mark. Then, when they click the check mark,
the partial is displayed, and the check mark becomes an "x" again.
Here is my strategy:
-- make a helper that toggles a style="display: none" inside the div
that contains my partial, depending on whether show / hide is set to 1
or 0 in my database for a given user
-- hook up my check marks to a link_to_remote action in my controller,
that toggles show / hide in the database, and does a page.replace_html
for my partial
(Code is below)
When I click once on my gif, my partial disappears. When I look at
the html source, the style="display: none" is not in the source -- I
have to refresh the entire page to see style="display: none"
When I click my gif again, my partial does not reappear. When I check
the source, I can see the partial -- but i have to do a page refresh
in order to see the partial in my browser.
Help very very much appreciated.
Charlie
helper
def hidden_div_if(condition, attributes = {} )
if condition
attributes["style"] = "display: none"
end
attrs = tag_options(attributes.stringify_keys)
"#{attrs}"
end
view
<div id="content_box_5"
<%hidden_div_if(@user_search_term.hide_newslistings == 1) %>>
action
def hide_newslistings
id = params[:id]
@search_term = SearchTerm.find(id)
@user_search_term = UserSearch.find_by_search_term_id(id)
## this toggles show / hide
if @user_search_term.hide_newslistings == 0
@user_search_term.hide_newslistings = 1
else
@user_search_term.hide_newslistings = 0
end
@user_search_term.save
## paginator
@user_newslisting_pages, @user_newslistings paginate(:user_newslistings,
:conditions => ["user_newslistings.search_term_id = ? and
user_newslistings.deleted = ''0''", id],
:include => :newslisting,
:order => ''modification_date DESC'',
:per_page => 5)
render :update do |page|
page.replace_html ''content_box_5'', :partial =>
''news_listings'', :url => {"page=?", page},
:layout => false
end
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---