由于我在操作前已登录检查,因此删除对象时无法使用redirect_back。
哪一种是将电流有可能存储在url某处,session helper然后在任何控制器中重定向到该值的最佳方法?
请帮助,此问题正在影响我所有关联的控制器。
重定向回使我可以编辑/显示,现在为零。
我目前正在从父级删除:
module SessionsHelper
# Logs in the given user.
def log_in(user)
session[:user_id] = user.id
end
# Remembers a user in a persistent session.
def remember(user)
user.remember
cookies.permanent.signed[:user_id] = user.id
cookies.permanent[:remember_token] = user.remember_token
end
# Returns the current logged-in user (if any).
def current_user
@current_user ||= User.find_by(id: session[:user_id])
end
# Returns true if the user is logged in, false otherwise.
def logged_in?
!current_user.nil?
end
# Forgets a persistent session.
def …Run Code Online (Sandbox Code Playgroud) 我正在使用 Rails 5,我想删除一组对象。在之前的帖子中,我读到“destroy_all”是真理和光明。我有两个对象数组,我将它们减去以获得第三个数组
unused_currencies = all_currencies - currencies_from_feed
unused_currencies.destroy_all
Run Code Online (Sandbox Code Playgroud)
但是在使用时出现destroy_all了这个错误:
NoMethodError: undefined method `destroy_all' for #<Array:0x007feea8878770>
Run Code Online (Sandbox Code Playgroud) Laravel Route::resource('countries', 'CountriesController'); 现在为DELETE工作
仅作为(单独)工作Route::delete('/countries/{country}/delete', 'CountriesController@destroy');
<div class="row">
<div class="col-12">
<h1>Details for {{ $country->countryName }}</h1>
<p><a href="/countries/{{ $country->id }}/edit">Edit</a></p>
<form action="/countries/{{ $country->id }}/delete" method="post">
<input name="_method" type="hidden" value="DELETE">
@method('DELETE')
@csrf
<button type="submit" class="btn btn-danger">Delete1</button>
</form>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
无法正常工作,我被卡在网址:http : //192.168.1.7 : 8000/countries/6/delete
说“ 404 |未找到”
我在这种Destroy()从未被调用的情况下运行。
unit Unit2;
interface
type
// Interface
ITest = Interface(IInterface)
function IsTrue() : Boolean;
end;
TmyClass = class(TInterfacedObject, ITest)
public
// Interface implementation
function IsTrue() : Boolean;
constructor Create();
destructor Destroy(); override;
end;
implementation
constructor TmyClass.Create();
begin
inherited Create();
end;
destructor TmyClass.Destroy();
begin
inherited Destroy();
end;
published
// Property
property IsItTrue: Boolean read IsTrue;
end.
Run Code Online (Sandbox Code Playgroud)
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms,
Vcl.Dialogs, Vcl.StdCtrls, unit2;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: …Run Code Online (Sandbox Code Playgroud)