Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

How can I include a model association in a JSON response in Rails? -


i've looked @ similar posts can't seem quite figure out.

i have following function works fine. listing model has foreign key called price_id maps price model , price_range column. price_id returned part of message object in json response.

how can return corresponding price_range value association instead of price_id value (as part of message obj, and keep other attributes)?

def update     @listing = listing.find(params[:listing][:id])      #if params passed in updating     if @listing.update_attributes(params[:listing])     #should return whole thing or what's needed?         json_response = {              "success" => @listing.save, #save db , assign true/false based on success...              "message" => @listing.attributes #use attributes show output content of @message obj, , not object called "message"         }          respond_to |format|              #json response             format.html { render:json => json_response }              format.xml { render :xml => @listing }               #normal response. consider leaving now?             #format.html { render :action => "detail" } #refresh page, new data in it. consider trying use redirect instead?             #format.xml  { head :ok }         end     end #end if   end 

add method in listing model price_range , call in serializable_hash

class listing    def price_range     price.price_range   end end 

like explain on comment can use delegate instead method :

class listing   delegate :prince_range, :to => price end 

in controller can :

   json_response = {          "success" => @listing.save, #save db , assign true/false based on success...          "message" => @listing.serializable_hash(:methods => [:price_range])     } 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -