Best practice - Passing instance variables or using params in Ruby on Rails views? -


according following example, what's best practice?

case 1

controller.rb ...

def index   ...   @group = params[:group]   @team = params[:team]   @org = params[:org]   ... end 

index.html.haml

= link_to @group, '#' = link_to @team, '#' = link_to @org, '#' 

case 2

controller.rb ...

def index   ...    ... end 

index.html.haml

= link_to params[:group], '#' = link_to params[:team], '#' = link_to params[:org], '#' 

or maybe there option, passing 1 instance variable of hash type...

thanks!

generally it's better idea split out parameters instance variables, if need cleaning on them. using params directly inside view bit messy, , has effect of needlessly tying view structure of incoming parameters.

it's controller's job intermediate between incoming parameters , view itself. should convert 1 format can make change parameters without affecting view, , view without changing requirements parameters.

it's unusual pass through parameters without doing kind of processing on them. of time, incoming parameters used fetch records database, or used in routing in capacity.

seeing 3 parameters being passed in , used literally on page not common use case. why passing these in instead of passing reference 1 of these things can used determine others?

for example:

@team = team.find_by_slug(params[:team_id]) @org = @team.org @group = @team.group 

this how rails applications constructed.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -