Haseeb Ahmad
Haseeb Ahmad

Reputation: 8730

How to send parameter from action in rendering method?

How to send parameter in render a view from action

respond_to do |format|
  if @donation.save
  else
    format.html { render :new,:locals => { :need_id => @need_id }}
  end
end

But need_id is accessble in new.html.erb How I pass this param?

Upvotes: 0

Views: 261

Answers (2)

ank
ank

Reputation: 88

If you have @need_id in the controller and this

format.html { render :new,:locals => { :need_id => @need_id }}

you can do <%= need_id %> in view file.

Upvotes: 0

Jagdeep Singh
Jagdeep Singh

Reputation: 4920

If you have already defined @need_id in your controller. It will be available in the corresponding view files as it is:

View file (.html.erb):

<%= @need_id %>

Upvotes: 1

Related Questions