Rails 4 Update Data Through View Page -


I currently have a watch page named "user" in my watch page, I am displaying a table in which The features removed from the user table include the first names, last names, last logins, administrators, etc. ... In the admin field, this user shows correct or incorrect from the table.

What I want to do is to create a drop down, which shows the user's current value to the administrator (true or false), and then be able to change this feature from the watch page. Currently, I have to use the console on the server to manually approve or cancel the administrator's privileges to give the value of the user a true or false value. Needless to say, it is inconvenient. I am still quite new to the rail and using scaffolds till this point, I am not sure how to complete it, and any advice will be greatly appreciated!

User schema:

  create_table "users", force: true do | T | "", Null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" "remember_created_at" t tatetime "email", default t.string. Integer "SIGN_IN_COUNT", default: 0, null: false t.datetime "current_sign_in_at" "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.datetime "created_at" t.datetime "updated_at" t tatetime. Boolean "administrator", default: false t.string "first_name" t.string "last_name" end   

Administrator controller:

  class AdminController & LT; ApplicationController before_action: authenticate_user! Deaf users @ User = User.All Order ('Last AN AC') End Df Report and End   

See user page:

  & lt; Table class = "table-table-hover-table-condensed" & gt; & Lt; Thead & gt; & Lt; TR & gt; & Lt; Th & gt; Last name & lt; / Th & gt; & Lt; Th & gt; First name & lt; / Th & gt; & Lt; Th & gt; Email & lt; / Th & gt; & Lt; Th & gt; Creation date & lt; / Th & gt; & Lt; Th & gt; Last signed in & lt; / Th & gt; & Lt; Th & gt; IP address & lt; / Th & gt; & Lt; Th & gt; Admin & lt; / Th & gt; & Lt; / TR & gt; & Lt; / Thead & gt; & Lt; Tbody & gt; & Lt;% @ users.each do | User | & Gt%; & Lt; TR & gt; & Lt; Td> & lt;% = user.last_name% & gt; & Lt; / Td> & Lt; Td> & Lt;% = user.first_name% & gt; & Lt; / Td> & Lt; Td> & lt;% = User.mail% & gt; & Lt; / Td> & Lt; Td> & Lt;% = user.created_at.strftime ("% -m /% -d /% y")%> & Lt; / Td> & Lt; TD & gt; & Lt;% = user.current_sign_in_at.strftime ("% - m /% - d /% y")%> & Lt; / TD & gt; & Lt; Td> & Lt;% = user.current_sign_in_ip% & gt; & Lt; / Td> & Lt; Td> & lt;% = user.admin% & gt; & Lt; / Td> & Lt; / TR & gt; & Lt;% end% & gt; & Lt; / Tbody & gt; & Lt; / Table & gt;    

You can complete it in different ways, for example, if the user is the administrator Or, if this is the case, you can trigger a link toggle_admin in the drop-down to delete the administrator.

Make the first route, in routes. RB:

  Resources: Users get: toggle_admin end   

In your view:

    

And in your controller, you can have something like this:

  def toggle_admin @ current_user.update_attribute: admin, (@ current_user.admin false? : True) end   

hmm ... yes, I do not know. could work. As you can see, I assume here that you have a the @current_user variable to pick the user variable, otherwise either from the url parameter in the controller or directly in these methods to send to user.id, Method.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -