regmiprem
regmiprem

Reputation: 735

ruby on rails send value through redirect

    @id =params[:ad]
   @empreasset = params[:check_box_id]
    case params[:commit]
    when 'delete'
      @empreasset.each do |empreasset|
        @em = Empreasset.find(empreasset)
        @em.destroy
  end
  @[email protected]
  @message = "#{@size} Employee asset(s) deleted sucessfully"
  respond_to do |format|

      format.html {redirect_to :action => :index, :id => @empreasset.ad}
      format.json {head :no_content}

end

Here (@empreasset.ad=@id) Also logic can be format.html {redirect_to :action => :index, :id => @id} It is also ok. But error occurs.. In controller index i have to send value of id. As @empreasset.ad has same value for all data. I need to send one @empreasset.ad value. But how can it be possible since @empreasset.ad is in array. How can i pick only one value of @empreasset.ad and send in

redirect :id => @empreasset.ad?

Upvotes: 0

Views: 265

Answers (2)

vijikumar
vijikumar

Reputation: 1815

Write one more line . [email protected]

then

format.html {redirect_to :action => :index, :id => empreasset.ad}

Upvotes: 0

Rodrigo Dias
Rodrigo Dias

Reputation: 1340

@empreasset is an array, right? To send one value of this array, use @empreasset.first.ad This will get the property ad of the first element of the array.

Upvotes: 1

Related Questions