Görünümümde listelenen veritabanından tüm öğelerin bir dizinine sahibim. Ben Raylar İşte 4. Ruby on kullanılarak veritabanında geçerli kaydı yok etmek için bir imha düğme oluşturmak istiyorum benim kodudur:Ruby'de bir yoksay düğmesiyle veri satırı silme
<div>
<h1>All Incomes</h1>
<% @user_incomes.each do |income| %>
<div>
<p><%= income.title %></p>
<p><%= income.description %></p>
<p><%= number_to_currency(income.amount) %>
<p><%= income.user_id %></p>
<%= button_to "Destroy", {action: "destroy", id: income.id}, method: :destroy, data: { confirm: "Are you sure?" } %>
</div>
<br />
<%end%>
</div>
My Gelir Denetleyici: Burada
class IncomesController < ApplicationController
before_action :authorize, only: [:new, :index, :show, :create]
def index
@incomes = Income.all #income refers to the db model income
@user_incomes = Income.all.where(:user_id=>current_user.id)
end
def show
@income = Income.find(params[:id])
end
def new
@income = Income.new
end
def create
@income = Income.create(income_params)
end
def destroy
@income.destroy
end
## Strong Parameters alias Rails 3's attr_accessible
private
def income_params
params.require(:income).permit(:title, :user_id, :description, :type, :amount)
end
def declare_income
@income = Income.find(params[:id])
end
end
benim rota dosyasıdır: Ben
rails generate scaffold
ile bir iskele kullanmak olsaydı raylarına newb
Rails.application.routes.draw do
get 'member_content/new'
#get 'sessions/new' ## this is generated with rails g controller sessions new
resources :sessions
resources :incomes
resources :users
resources :abl_deductions
get 'main/index'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
get 'signup', to: 'users#new', as: 'signup'
get 'login', to: 'sessions#new', as: 'login'
get 'logout', to: 'sessions#destroy', as: 'logout'
get 'content', to: 'member_content#new', as: 'content'
get 'add_income', to: 'incomes#new', as: 'add_income'
get 'add_deduction', to: 'abl_deductions#new', as: 'add_deduction'
get 'deductions', to: 'abl_deductions#index', as: 'deductions'
end
, bu eylem için daha kolay olurdu?
Denetleyicinizde bu aramayı kesiştiren bir "imge" yöntemine sahip olmanız ve bu düğmeyi doğru URL'ye bağlamanız gerekir. Rotalarınızı – tadman
gönderin. – toddmetheny
Düğme, doğru URL’ye nasıl bağlanır? URL'ye gitmek yerine yöntemi arayabilir miyim? Ayrıca bu dizin sayfasının kaydı sildikten sonra yenilenmesini istiyorum. –