Let admin can choose user attributes checkbox

This commit is contained in:
Wen-Tien Chang 2010-03-15 16:13:26 +08:00
parent a40b117fbe
commit 263da6aa9f
5 changed files with 28 additions and 8 deletions

View File

@ -2,11 +2,8 @@ class ApplicationController < ActionController::Base
protect_from_forgery protect_from_forgery
helper :all helper :all
before_filter :set_locale before_filter :set_locale
filter_parameter_logging :password
Liquid::Template.register_filter(SnippetFilter) Liquid::Template.register_filter(SnippetFilter)
def render_liquid_page def render_liquid_page

View File

@ -3,7 +3,7 @@ class User
devise :authenticatable, :recoverable, :rememberable, :trackable devise :authenticatable, :recoverable, :rememberable, :trackable
# key :use_attributes key :use_attributes, Array
def method_missing(method) def method_missing(method)
safe_read(method) safe_read(method)

View File

@ -11,6 +11,7 @@
<%= stylesheet_link_tag "ie", :media => "screen, projection" %> <%= stylesheet_link_tag "ie", :media => "screen, projection" %>
<![endif]--> <![endif]-->
<%= yield :page_specific_css %> <%= yield :page_specific_css %>
<%= csrf_meta_tag %>
</head> </head>
<body> <body>
<div id="container"> <div id="container">

View File

@ -11,6 +11,7 @@
<%= stylesheet_link_tag "ie", :media => "screen, projection" %> <%= stylesheet_link_tag "ie", :media => "screen, projection" %>
<![endif]--> <![endif]-->
<%= yield :page_specific_css %> <%= yield :page_specific_css %>
<%= csrf_meta_tag %>
</head> </head>
<body> <body>
<div id="container"> <div id="container">

View File

@ -1,4 +1,19 @@
<div id="select_user_attributes">
<% @user_attributes.each do |ua| %> <% @user_attributes.each do |ua| %>
<%= check_box_tag "user[use_attributes][]", ua.key, @user.use_attributes.include?(ua.key) %> <%= ua.name %>
<% end -%>
<%= hidden_field_tag 'user[use_attributes][]','' %>
</div>
<div>
<p>
<%= f.label :email %>
<%= f.text_field :email %>
</p>
</div>
<% @user_attributes.each do |ua| %>
<div id="attribute_<%= ua.key %>"<%= raw(' style="display: none;"') unless @user.use_attributes.include?(ua.key) %>>
<h3><%= ua.name %></h3> <h3><%= ua.name %></h3>
<% ua.attrs.each do |attr| %> <% ua.attrs.each do |attr| %>
@ -7,9 +22,15 @@
<%= f.send(attr["type"], "#{ua.key}_#{attr["key"]}" )%> <%= f.send(attr["type"], "#{ua.key}_#{attr["key"]}" )%>
</p> </p>
<% end -%> <% end -%>
</div>
<% end -%> <% end -%>
<p> <% content_for :page_specific_javascript do %>
<%= f.label :email %> <script type="text/javascript" charset="utf-8">
<%= f.text_field :email %> $(document).ready(function(){
</p> $('#select_user_attributes input').click(function(){
$("#attribute_"+this.value).toggle();
});
});
</script>
<% end -%>