我面临的问题是,当我点击查看此应用程序时,它只是在每次这是资金表中的第一个ID时打开相同的应用程序。但是也存在其他应用程序。如果我点击此应用程序的任何视图,每次在资金表中首次应用时,相同的应用程序都会打开。请帮忙。
show.html.erb(儿童)
<div class="col-sm-9 col-xs-12">
<div class="content" role="main" id="main-content">
<article>
<div ><h1 align="center"><%= @child.firstname %></h1>
<hr>
<p>First Name: <%= @child.firstname %></p>
<p>Last Name: <%= @child.lastname %></p>
<p>Date of Birth:<%= @child.dateofbirth %></p>
<p>Gender: <%= @child.gender %></p>
<p>
<%= link_to "Apply for funding", new_funding_path, class: "btn btn-primary btn-2x" %>
<%= link_to "Edit the child", edit_child_path(@child), class: "btn btn-primary btn-2x" %>
<%= link_to "Delete this child", child_path(@child), method: :delete, data: {confirm: "Are you sure you want to delete?"}, class: "btn btn-primary btn-2x" %>|
<%= link_to "Add another child", new_child_path, class: "btn btn-primary btn-2x" %></p>
<hr>
**<h1 align="center">Applied</h1>**
<% @child.fundings.each do |funding| %>
<p><strong>Status: </strong> |
<strong>Type of Activity: </strong><%= funding.type_of_activity %> |
<strong>Start Date: </strong><%= funding.activity_start_date %>|
**<%= link_to "View this application", Funding.find_by(params[:id]), class: "btn btn-primary btn-2x" %>**
</p>
<% end %>
<div class="clearfix"></div></div>
</article>
</div>
<!-- .content -->
</div>
fundings_controller.rb
class FundingsController < ApplicationController
def index
@fundings=Funding.all
end
def show
@funding = Funding.find(params[:id])
end
def new
@funding = Funding.new
end
def create
@funding = Funding.new(funding_params)
puts child_user
@funding.child = Child.find(child_user.ids[0])
if @funding.save
flash[:success] = "Thankyou for submitting"
redirect_to funding_path(@funding)
else
render 'new'
end
end
def edit
@funding = Funding.find(params[:id])
end
def update
@funding = Funding.find(params[:id])
if @funding.update(funding_params)
flash[:success] = "Your application is updated successfully"
redirect_to funding_path(@funding)
else
render 'edit'
end
end
def destroy
@funding = Funding.find(params[:id])
@funding.destroy
flash[:danger] = "Application was successfully cancelled"
redirect_to child_path(@child)
end
private
def funding_params
params.require(:funding).permit(:describe_activity, :type_of_activity, :season, :activity_details, :name_of_organisation, :activity_start_date, :number_of_weeks, :days_per_week, :hours_per_day, :program_registration_cost, :family_contribution, :other_funds, :other_fund_provider, :amount_requested, organisations_attributes: Organisation.attribute_names.map(&:to_sym).push(:_destroy))
end
end
答案 0 :(得分:1)
如果我理解正确,你的意思是:
update
您目前正在执行<%= link_to "View this application", funding, class: "btn btn-primary btn-2x" %>
,这与Funding.find(params[:id])
中传递的资金ID基本相同。