Fields that are hidden in the UI


(John R Epperson) #1

Continuing the discussion from Listing associated content, showing related and asset field values:

You mention here that there are ways of hiding fields? I added some comments to my app (blog + podcast listing) and don’t want the comments to appear in the edit screen. I’ve made a cursory glance and that’s how I found this. Any suggestions? Would you talk through what that looks like?

Thanks!


(Aaron Russell) #2

Hi @kirillian

To achieve this we can use Rails’ store_accessor method to add attributes to PushType’s json field_store.

class Page < PushType::Node

  store_accessor :field_store, :comments

end

The above will add a comments getter and setter methods to the node instance, and also allow mass assignment through update_attributes etc. But there will be nothing rendered on the node edit screen to indicate that this attribute exists.


(John R Epperson) #3

Two questions…one, how do I get a code block? I can’t seem to find the WYSIWYG control to do that…

Question 2, I actually WANT the relationship portion of field, so maybe I should be using native has_many and belongs_to? I actually don’t have a lot of experience with using store_accessor yet. That’s the :serialized replacer right?


(John R Epperson) #4

Ok, so a followup to this question. I did some playing around with things and discovered adding basic belongs_to and has_many relationships seems to work as expected. It ends up making things slightly less clunky too. I guess I just wasn’t thinking things through as well as I could have. Thanks for the response.


(Aaron Russell) #5

Yes if you have a plain old Comment model and you want that to belong to a node model then you can use Rails’ has_many and belongs_to - just be aware that PushType uses GUIDs so the foreign key on the Comment model should be the appropriate type.

how do I get a code block? I can’t seem to find the WYSIWYG control to do that…

The wysiwyg editor should have a “Paragraph Format” button which lists the heading levels, normal paragraphs, blockquotes and code.


(John R Epperson) #6

So it took me a while to respond to this…unintentional. I was actually referring to the code block in Discuss. I can’t seem to create a block using this editor.