Reputation: 349
I have the contact details in the front page. Is it possible to allow the admin to change these details dynamically from the back-end?
contact.html.erb
<h3>Contact</h3>
<p>Email: [email protected]</p>
<p>Twitter: @example</p>
Upvotes: 0
Views: 127
Reputation: 2986
You'll need to store the contact details in a table in the database, and set up a model for this. You can't set up ActiveAdmin to edit plain text in one of your view templates.
Once you have your model you can easily use ActiveAdmin for editing the single row that you need for these details.
rails g model ContactDetail email:string twitter:string
Then create a single row with your defaults:
> rails console
ContactDetail.create(email: "[email protected]", twitter: "@example")
Then put this in the controller for your contact page:
@contact_detail = ContactDetail.first
And tweak the view:
<h3>Contact</h3>
<p>Email: <%= @contact_detail.email %></p>
<p>Twitter: <%= @contact_detail.twitter %></p>
Now in your app/admin/contact_details.rb you just need:
ActiveAdmin.register ContactDetail do
index do
column :email
column :twitter
end
end
Upvotes: 2