I'm currently trying to add a privacy page to allow my users to modify their privacy settings. I'm using rails-settings to store those settings but creating a layout and updating them is causing me issues.
I created a new page privacy.html.erb
, and have it rendering a new partial _privacy.html_erb
. The problem is that I cannot simply map the values as if they were just columns.
As in, I can't do <%= f.text_field :name %>
as the settings structure is different.
// user.rb has settings stored in this manner.
has_settings do |s|
s.key :global, :defaults => { :visibility => PRIVACY_ANYONE }
end
Which can be easily gotten through this call.
return settings(:global).visibility
> returns PRIVACY_ANYONE
So, instead of using form_for
, I could instead use form_tag
and manually add each field and values. But that sounds like a hacky solution.
And how do I go about saving/updating these values?
Within routes, I've added two routes to get the edit page, and have a post, which does call the correct UserController methods, but the post seems to clear the user so I can't do anything.
// routes.rb
resources :users do
get 'privacy'
post 'privacy' => 'users#privacysave'
end
- What would be the best way to handle this case?
- Should I move away from rails-settings and just add another table?
- And how do I update those values?
Aucun commentaire:
Enregistrer un commentaire