ruby - How to get values in show action in rails controller -
i have access parameters in nested attributes..... below code.
<%= link_to "invoice", user_invoice_path(@user, invoice) %>
how access user , invoice in invoice controller show action.
def show @user = user.find(params[:user_id]) @invoice = invoice.find(params[:id]) end
user model:
class user < activerecord::base has_many :invoices end
invoice model:
class invoice < activerecord::base belongs_to :user end
i know how works when not nested.... can anyone, please help?
if understand correctly, can't find @user
or @invoice
in way.
please debug show
action , find params
follows,
{"action"=>"show", "controller"=>"invoices", "user_id"=>"307", "id"=>"359"}
so write show action like,
def show @invoice = invoice.find(params[:id]) @user = user.find(params[:user_id]) end
there may better ways find objects in controller action. basic approach have consider instead of tried.
Comments
Post a Comment