开发者

Rails 3 - Return the id of each nested attribute that was created

开发者 https://www.devze.com 2023-04-02 22:57 出处:网络
Is there anyway for me to return the id\'s of the nested attributes when they are created? right now i return the id of the parent this way. Where @report.id is the parent.

Is there anyway for me to return the id's of the nested attributes when they are created?

right now i return the id of the parent this way. Where @report.id is the parent.

format.json { render :json => { :success => 开发者_JS百科true, :report_id => @report.id } }

I would like to do something like this....

format.json { render :json => { :success => true, :report_id => @report.id, :the_ids_for_the_created_nested_attributes => @report.icons.ids } }


To get the ones that were just created, keep the ones that existed before the edit, and take the difference.

And names like "the_ids_for_the_created_nested_attributes", particularly in an example, would probably be better expressed as something like "icon_ids", if for no other reason than we don't have to scroll as much to see what you really meant.


Credit to agmcleod and rails docs

Answer: Just put @report.icons in the response, then parse the json.

format.json { render :json => { :success => true, :report_id => @report.id, :report_icons => @report.icons } }
0

精彩评论

暂无评论...
验证码 换一张
取 消