show-index with current user - why?

26 views
Skip to first unread message

tonym

unread,
Oct 31, 2012, 12:46:01 PM10/31/12
to hobo...@googlegroups.com
This one's baffled me - just can't figure out why show-index needs 'with="&current_user"?
I first came across this in the agility tutorial, found a fix here and thought nothing of it.  But with my project, it's become a problem...
I have all my permissions sorted in my model - admin can view all records, standard users view only the records they've created.
The permissions worked fine, the views return the right records, until I customized the page through <show-index>

<show-index> always returns blank, unless I use the 'with="&current_user"  (that's the fix, discuss here in another thread).
But if I use the 'with', then the admin can only view their own records, thus breaking my model...  Can I get the index page up without using 'with', and use the rules in my model?  

Here's my view code...

<if test="&current_user.signed_up?">
  <index-page with="&current_user">
   <top-page-nav: replace /> 
   <bottom-page-nav: replace /> 
    <collection: replace>
      <table-plus:my_venues fields="name, venuetype, local_area, telephone, approval" />
    </collection:>
  </index-page>
</if>
<else>
  <page title="No Access">
  </page>
</else>

Thanks, Anthony.

Vivek Sampara

unread,
Oct 31, 2012, 1:42:21 PM10/31/12
to hobo...@googlegroups.com
Anthony, 

You can associate my_venue model with a user and set the view/create/delete/update permissions in the model itself , then you dont have to do call the test current_user.signed_up in the view. 

  In the model 

    belongs_to :user , :creator => true

  def create_permitted?
    acting_user.administrator? || user_is?(acting_user)
  end

  def update_permitted?
    acting_user.administrator? || user_is?(acting_user)
  end

  def destroy_permitted?
    acting_user.administrator? || user_is?(acting_user)
  end

  def view_permitted?(field)
    acting_user.administrator? || user_is?(acting_user)
  end

 Im not sure about the term but i think its the 'filter' . this filter will let then model assign to a particular "signup user" 

Vivek  


--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/hobousers/-/A3ZpdWAO9NYJ.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.

tonym

unread,
Oct 31, 2012, 2:57:30 PM10/31/12
to hobo...@googlegroups.com
Thanks for your help Vivek, but that's not my problem,
The 'signed_up?' check is purely so I can give a friendly message to those who aren't logged in.  
It's the <show-index> that is the problem.  It returns blank unless I use 'with' - but I have a defined model that is for that purpose - the 'with' is breaking my model, I just don't need it in theory, but I can't get it to work without it...

this is my view model...

  def view_permitted?(field)
    acting_user.administrator? || (acting_user.signed_up? && user_is?(acting_user))
  end



Anthony.

Bryan Larsen

unread,
Oct 31, 2012, 3:07:11 PM10/31/12
to hobo...@googlegroups.com
You've got the colon form when specifying the collection:

<table-plus:my_venues ...

Which is essentially equivalent to

<table-plus with="&current_user.my_venues" ...

because you specified the with="&current_user" further up.

If you removed both the with="&current_user" and the :my_venues, then
the table plus should use whatever your controller action puts into
the "this" variable. So you'd probably want to define an index
action in your controller that looks something like:

def index
self.this = ....
hobo_index
end

Bryan

tonym

unread,
Oct 31, 2012, 4:03:01 PM10/31/12
to hobo...@googlegroups.com
Bryan, you are a star!  It was the <table-plus:my_venues... causing the problem - often the smallest of things get us (especially noobies!).

Cheers, Anthony.
Reply all
Reply to author
Forward
0 new messages