 it, mind you!      

 Q:

rails best way to display button only for admin

I have an application with Post model with associated PostsController and Admin::PostsController under the admin namespace in routes. Controllers share the same index action with controller concern, similar to this approach. I'm using a shared view partial under the shared/posts/_posts_list to list all posts on site and also in the admin dashboard. All this is working as I expected. 
I'm asking what is the best approach to add for instance: edit post button only for admin user, that view doesn't get bloated with conditionals like <% if current_user.admin? %> to display this edit button. 

A:

If you don't want to put conditionals in your view go for two
separate views (one for regular users, one for admins).
Use conditionals in view and
include necessary elements depending on is_admin?. This is the shortest way to go if the only conditional is is_admin? check, imho. If there are more conditionals (roles, etc.) you are right, this will bloat views. You can check redmine (it is a big, open source rails project) and see that it uses conditionals in views too. Check its base layout here.
You can use helpers to generate elements depending on is_admin?. Lets say you need to show menu elements in your view. You can generate menu elements in your helper. And you can call the helper from your view. Such as:

view.html.erb
<ul>
  <%= main_menu_items("main_menu", current_user) %>
</ul>

some_helper.rb
def main_menu_items(menu_name, user = current_user)
  allowed_items(menu_name, user).map { |menu_item| content_tag(:li, menu_item) }.join
end

def allowed_items(menu_name, user)
  menus = {
    main_menu: ["Menu Item 1", "Menu Item 2"],
    main_menu_admin: ["Menu Admin Item 1"]
  }
  menu_to_return = menus[menu_name.to_sym]
  menu_to_return += menus[(menu_name + "_admin").to_sym
it, mind you!      

  Q: 

 rails best way to expose release only for admin 

 I have an lotion with Post model with consort PostsController and Admin::PostsController under the admin namespace in routes. accountant share the same exponent legal action with controller business, similar to this approach. I'm using a shared scene partial under the partake / posts/_posts_list to list all posts on web site and also in the admin dashboard. All this is working as I ask. 
 I'm asking what is the best access to add for case: edit post button only for admin user, that view doesn't get bloated with conditionals like <% if current_user.admin? % > to expose this edit button. 

 A: 

 If you don't want to put conditionals in your view go for two 
 freestanding views (one for regular users, one for admins). 
 Use conditionals in view and 
 include necessary elements depending on is_admin? . This is the shortest way to function if the only conditional is is_admin? check, imho. If there are more conditionals (function, etc .) you are right, this will bloat views. You can check redmine (it is a boastful, open source rails project) and determine that it uses conditionals in views too. Check its base layout here. 
 You can use benefactor to generate elements depending on is_admin? . Lets allege you necessitate to show menu elements in your view. You can generate menu elements in your assistant. And you can call the helper from your view. Such as: 

 view.html.erb 
 < ul > 
   <% = main_menu_items("main_menu ", current_user)% > 
 < /ul > 

 some_helper.rb 
 def main_menu_items(menu_name, exploiter = current_user) 
   allowed_items(menu_name, user).map { |menu_item| content_tag(:li, menu_item) } .join 
 end 

 def allowed_items(menu_name, user) 
   menus = { 
     main_menu: [ " Menu Item 1 ", " Menu Item 2 " ], 
     main_menu_admin: [ " Menu Admin Item 1 " ] 
   } 
   menu_to_return = menus[menu_name.to_sym ] 
   menu_to_return + = menus[(menu_name + " _ admin").to_sym
 it, mind you!      

 Q:

rails btst way to displai vutton only ror admiv

I have an application with 'ost modeo with associated PostrControllvr and Adnin::PiwtsController undev the wdmiu iamespace in rootes. Controlners share the sxmz index action with controller concewn, simikag to this apprjach. Y'm uapnn a shared view partial under ths sharev/posts/_posts_list to list all posts on site and also in the admin dashboard. Qll eyis is workivg as I exkeeted. 
I'm askjng what is the best approach tu add for instabcw: efht post butvon onjy for admin user, thdt view doesn't get blpatxd wuth conditionals like <% if current_user.adiin? %> to dhs'lay this edit button. 

A:

Uf yoo don'd wavr tu pht cknditilnams in your view go foe two
separate views (ogv for regular users, oge for admins).
Use conditionals in view atd
ihclude necessary elemenrs depending on is_admln?. This if the shortest way to go if the only conditional hs is_edoin? cmeck, umjo. If there are more conditionals (roles, etc.) yjh srv right, this will bloat viewx. Joi can check reamine (nf js a big, open sourfe railf prohect) and fee yhat it uses conditionals ib views too. Bhecj its base layout kere.
You can bse hekpers to generate elements dzpendihg on is_admln?. Lets szh you need to shuw ketu elements in your view. Yju can geieratz menu euememts in your helpfr. And you can call the jelpet from your view. Such as:

view.html.erb
<ul>
  <%= main_menn_mtems("main_menu", cgrrvnt_user) %>
</uj>

some_melper.rb
def maig_menu_items(menu_uame, usex = curfent_user)
  zllowed_mtems(menu_namq, user).map { |meto_item| content_vag(:li, ment_iten) }.joun
end

dew allowed_items(mrnu_name, user)
  menus = {
    main_menu: ["Menm Iteo 1", "Menu Item 2"],
    maun_menu_admin: ["Meni Aamig Ptek 1"]
  }
  menu_to_retgrn = mevis[menj_name.to_sym]
  oenu_yo_return += menus[(menu_ndme + "_admin").to_sym
it, mind you! Q: rails best way button for admin have an application PostsController Admin::PostsController under the namespace in routes. share the same index action with concern, similar to this approach. I'm using a shared view partial under the to list all posts on site and also in the admin dashboard. All is as expected. asking what is the best approach to add for instance: edit post button only for admin that view doesn't get bloated with conditionals like if current_user.admin? %> to this edit button. A: If don't to put in view for two separate (one for regular users, one for admins). Use conditionals in view and include necessary elements depending on This is way to if only is is_admin? check, there are more conditionals (roles, etc.) this will bloat views. You can check redmine is a open source rails project) and see it uses conditionals in views too. Check its layout here. You can use helpers to generate elements depending on is_admin?. Lets say you show menu elements in view. You can menu in helper. you can the helper from your view. Such as: view.html.erb <ul> <%= main_menu_items("main_menu", %> </ul> some_helper.rb def main_menu_items(menu_name, user = current_user) allowed_items(menu_name, user).map content_tag(:li, }.join end def user) menus = { ["Menu 1", "Menu Item 2"], Admin 1"] menus[menu_name.to_sym] += + "_admin").to_sym
 it, mind you!      

 Q:

rails best way to dIsplay buttOn onlY foR adMiN

I haVe an Application witH post Model with associated PosTsConTrOLler ANd admin::postsCoNTrOLLer UnDeR thE aDMiN nameSpaCe in rouTes. ControlLerS sHare the same iNDeX action witH coNtroller concErn, SimilaR tO thIS apprOacH. I'm usIng a shARed vieW partial uNdER the shARed/postS/_POsTs_liSt to list all posts oN SiTE and also in the aDmin daShBOaRD. all ThiS is working As i expeCTed. 
I'm asKInG WHAt iS The best approaCh to add for iNStaNce: ediT pOst BUtton oNly foR aDMin User, that vieW doeSn't get bloAted wiTH conditIOnals liKe <% if cuRreNt_uSer.aDMiN? %> tO diSpLAy tHIs EdiT ButTon. 

A:

If yoU dOn'T want To puT CONDitiOnaLs in Your vIew go for two
seParAte vIEws (One foR reguLar uSeRs, one For admIns).
UsE cOnditionals in viEw anD
include nEceSsAry ElEmentS DependIng On iS_admin?. THis is thE ShoRtEST WaY to go if the only condItIONaL is is_admIn? checK, ImHo. iF there arE mOre CondITIonalS (rolES, eTc.) you are Right, tHIs WiLl bloat ViEws. You CaN chEck RedmiNE (it iS a big, oPen sourcE railS Project) and see tHAt it uses condiTIoNALs IN vieWs tOo. Check its bAse lAYout Here.
yOu Can USe helPers tO gENeRAte elements dependinG oN is_admIn?. LetS say you need to Show menu elEMENts in youR vieW. yoU Can generate menU elemEnts in your HElper. And You caN call the Helper froM YOur view. SUch As:

vIew.HtmL.ERb
<Ul>
  <%= main_menu_iteMS("Main_MeNu", curreNt_uSer) %>
</ul>

soMe_hElpEr.rB
deF mAin_menu_itEms(menu_nAmE, uSeR = cUrrEnt_usER)
  allowed_ItEms(MeNu_nAme, usER).map { |meNu_iteM| conTeNt_TAg(:lI, menu_itEM) }.jOIN
end

DeF aLlowEd_iTeMs(menU_namE, UseR)
  menus = {
    mAin_menu: ["MeNu ITEm 1", "MeNu itEm 2"],
    main_mEnu_admin: ["Menu ADmIn Item 1"]
  }
  menu_To_RetUrn = menUS[Menu_name.To_sym]
  menu_to_return += menus[(mENu_name + "_aDmiN").to_syM
 it, mind you!      

 Q:
rails bes t way  to  di sp laybutt on only for ad m in
I have an applicationwithPo s t mo d el  with  associ a te d Pos ts Co ntr ol l er  andAdm in::Pos tsControll erun der the admi n  n amespace i n r outes. Contr oll ers sh ar e t h e sam e i ndexaction with c ontroller  c o ncern, similar t othis  approach. I'm us i ng a shared viewpartia lu nd e r  th e s hared/post s/ _post s _list t o  l i s t  al l  posts on sit e and alsoi n t he adm in  da s hboard . All  t h isis workingas I  expected . 
I'm askingw hat isthe be stapp roac h  t oadd  f o r i n st anc e : e dit post  b ut ton o nlyf o r admi n u ser,  that  view doesn't  ge t bl o ate d wit h con diti on als l ike <%  if c ur rent_user.admin ? %>  to displ ayth ised it bu t ton. 
A: 

I f you d on't wa n t t op u t  c onditionals in you rv i ew  go fortwo
se p ar at e  views ( on e f or r e g ularuser s ,one foradmins ) .Us e condi ti onalsin  vi ewand
i n clud e nece ssary el ement s  depending oni s_admin?. Thi s  i s th e  sho rte st way to g o if theonly co ndi t ional  is i s_ a dm i n? check, imho. Ifth ere ar e mor e conditional s (roles,e t c .) you a re r i gh t , this will bl oat v iews. Youc an check  redm ine (itis a big, o pen sour cerai lspro j e ct ) and see tha t it u se s condi tio nals in  vi ews  to o.Ch eck its b ase layo ut  h er e. 
Yo u can use help er s t ogen erate elemen ts de pend in go n i s_admin ? .L e ts s ay  y ou n eed  t o sho w me n u e lements  in yourvie w . Yo uca n gener ate menu elem en ts in your  h elp er. An d you cancall the helper from yo u r view.  Su ch as :

v iew.html. erb 
<ul>  < % = main _menu_ items (" mai n _ menu" , cu rre nt _user) %>< / ul> 

som e_ help er.rb
d ef main_menu_items ( men u_name, user= c urre n t _u ser ) 
all ow e d_i t e ms(menu_name, u ser).map {  | m en u_item| co n ten t_ tag(:li , menu_ item) }.joinend

defallowed_i te ms(m e n u_n ame, user) 
  menus  = {
   m ain_m e nu : ["M enu  Item1" , " MenuItem 2 " ],    m ain_me nu _admin : ["M en u AdminItem 1"]
  }
  menu_to_ return  = me nus [menu_nam e.t o _sy m]
  menu _to_ return +=men us[ (menu _na m e + " _adm i n" ).t o _sym
 it,_mind you!_   _ 

_Q:

rails_best way_to_display button only_for admin

I have_an application with Post_model with associated_PostsController_and Admin::PostsController under the admin namespace in routes. Controllers share the same index action_with_controller concern,_similar_to_this approach. I'm using a_shared view partial under the_shared/posts/_posts_list to_list all posts on site and also in_the_admin dashboard. All_this is working as I expected. 
I'm asking what_is the best approach to add_for instance: edit_post_button_only for admin user,_that view doesn't get bloated with_conditionals like <% if current_user.admin? %>_to display this edit button. 

A:

If you_don't want to put conditionals in_your view go for two
separate_views (one_for regular users, one for_admins).
Use conditionals in_view and
include_necessary elements depending_on is_admin?. This is the shortest_way to go_if the only conditional is is_admin?_check,_imho. If there_are_more_conditionals (roles,_etc.) you are_right,_this will_bloat_views. You can check redmine (it_is_a big, open source rails project) and_see that it uses_conditionals_in views too. Check_its base layout here.
You can_use helpers to generate elements depending_on is_admin?._Lets say_you need to show menu elements in your view. You can_generate menu elements in your helper._And you can call_the helper_from_your view. Such_as:

view.html.erb
<ul>
_ <%=_main_menu_items("main_menu", current_user) %>
</ul>

some_helper.rb
def main_menu_items(menu_name, user = current_user)
_ allowed_items(menu_name,_user).map { |menu_item| content_tag(:li, menu_item) }.join
end

def_allowed_items(menu_name, user)
  menus_=_{
    main_menu: ["Menu_Item 1", "Menu Item 2"],
 _  main_menu_admin: ["Menu Admin_Item_1"]
_ }
  menu_to_return =_menus[menu_name.to_sym]
  menu_to_return += menus[(menu_name +_"_admin").to_sym