Показать полное приложение, когда я нажму на Просмотреть это приложение - PullRequest
0 голосов
/ 23 мая 2018

Проблема, с которой я сталкиваюсь, заключается в том, что когда я нажимаю на кнопку просмотра этого приложения, оно просто открывает одно и то же приложение каждый раз, когда это первый идентификатор в таблице финансирования.Но существуют и другие приложения.Если я нажимаю на любое представление этого приложения, то одно и то же приложение открывается каждый раз, когда это первое приложение в таблице финансирования.пожалуйста, помогите.

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

1 Ответ

0 голосов
/ 23 мая 2018

Если я правильно понимаю, вы имели в виду:

<%= link_to "View this application", funding, class: "btn btn-primary btn-2x" %>

В настоящее время вы делаете Funding.find(params[:id]), что в основном совпадает с идентификатором финансирования, который был передан в fundings#show.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...