user9700954
user9700954

Reputation:

Display full application when I click on View this application

the problem I am facing is when I click on view this application it just opens the same application every time that is the first ID in the funding table. But there are other applications existing as well. If I click on any view this application the same application opens up every time that is first application in the funding table. please help.

show.html.erb (children)

<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

Upvotes: 0

Views: 48

Answers (1)

Biwek
Biwek

Reputation: 994

If I understand correctly, did you mean to do:

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

You're currently doing Funding.find(params[:id]), which is basically the same funding id thats been passed in fundings#show.

Upvotes: 1

Related Questions