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.

ruby on rails - Passing parameters into model -


rails 3.0.3 ruby 1.9.2p0

the problem:

i have users table has many items, item(s) in turn therefore belongs users.

in model item.rb attempt save item along value user.id have:

self.user_id = @user.id 

this give me error

called id nil, mistakenly 4 -- if wanted id of nil, use object_id 

this causing confusion can't find in show.html.erb 'wraps' page <%= @user.id %> displays correct id on page

many in advance

** edit ** shorten action action upon want parameter passed

class itemscontroller < applicationcontroller    def redirect     @item = item.find_by_shortened(params[:shortened])     if @item       #redirect_to @item.original       redirect_to @item.original     else       redirect_to :shorten     end   end    def shorten     @host = request.host_with_port     @user = current_user 

you need load @user model in every action require access it. having render in show action not guarantee loaded in update action.

usually need have in controller:

class userscontroller < applicationcontroller   before_filter :load_user, :except => [ :index, :new, :create ]    # ...  protected   def load_user     @user = user.find(params[:user_id] || params[:id])   rescue activerecord::recordnotfound     render(:text => 'record not found')   end end 

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 -