我已经设法创建一个仅用于注册和登录的应用程序.目前,我允许用户通过邮件帐户激活(遵循本教程:https://www.railstutorial.org/book/account_activation_password_reset and by 'rails生成控制器AccountActivations --no-test-framework')但我希望管理员能够激活或停用用户.在我的用户模型中,我设法定义了两种方法:
def activate_account!
update_attribute :is_active, true
end
def deactivate_account!
update_attribute :is_active, false
end
Run Code Online (Sandbox Code Playgroud)
在我的用户部分视图上,我设法
<% if current_user.admin? && !current_user?(user) %>
<%= button_to "Deactivate", user, data: { confirm: "Are you sure?" } %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我的路线看起来像这样:
get 'password_resets/new'
get 'password_resets/edit'
root 'static_pages#home'
get 'help' = 'static_pages#help'
get 'about' = 'static_pages#about'
get 'contact' = 'static_pages#contact'
get 'signup' = 'users#new'
get 'login' = 'sessions#new'
post 'login' = 'sessions#create'
delete 'logout' = 'sessions#destroy'
resources :users
resources …Run Code Online (Sandbox Code Playgroud) 我是HAML的新手,我有一个错误:Illegal nesting: nesting within plain text is illegal..目前,我正在尝试将我的erb更改为haml,但它无法正常工作.这是我的问题.
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<h2 class="mbs">New Subscription
</h2>
<%= simple_form_for :subscription, :url => subscribe_subscription_path(@plan.id), :id => "checkout-form" do |f| %>
<% if current_user and !current_user.has_payment_info? %>
<%= render 'customer_form'%>
<% end %>
<br/>
<p> Please enter payment details: </p>
<div id="payment-form"></div>
<div id="coinbase-container-id"></div>
<div class="form-actions">
<%= f.submit t(:subscribe), :class => 'btn btn-primary' %>
</div>
<script charset="utf-8" type="text/javascript">
var clientToken = "<%= @client_token %>";
braintree.setup(clientToken, "dropin", {
container: "payment-form",
coinbase: { container: "coinbase-container-id" …Run Code Online (Sandbox Code Playgroud) 我正在尝试根据此功能存储多个项目:
onclick="s(iId)"
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的功能:
function s(i_id) {
var items = [];
items.push(i_id);
localStorage.setItem("i", JSON.stringify(i));
}
Run Code Online (Sandbox Code Playgroud)
问题是它只在点击按钮时存储一个 id,每次点击刷新。我怎样才能让它存储多个ID?