logo
down
shadow

Rails admin show username instead of User #5


Rails admin show username instead of User #5

By : Alex Baratti
Date : November 22 2020, 10:33 AM
this one helps. This will work in list views when in tabular format. See the rails admin docs for additional detail.
code :
config.model "Post" do
  list do
    field :title
    field :body
    field :created_at
    field :user do
      pretty_value do
        value.username
      end
    end
  end
  edit do
    field :user_id do
      formatted_value do
        value.try(:user).try(:username)
      end
    end
  end
end


Share : facebook icon twitter icon
Show only username of user with ruby on rails

Show only username of user with ruby on rails


By : user3629595
Date : March 29 2020, 07:55 AM
Any of those help Looks more like an array of objects to me (not familiar with the gem you are using).
Does something like this work:
code :
<% current_user.pending_invited_by.each do |user| %>
  <%= user.username %>
<% end %>
Re-direct user to an admin.php page when admin username and password is provided

Re-direct user to an admin.php page when admin username and password is provided


By : Mateusz
Date : March 29 2020, 07:55 AM
will help you I am trying to make a admin.php page open up, upon providing the login system with an admin username and password. Here is what I have so far to re-direct the user to the home page, but I'm not sure if my code is right. I have tried using a if statement, but I don't know if I incorporated it right. I have my database written in mySQL, and the admin login and password are stored in slot '1' in the database. I'm pretty new to PHP and all the mySQL stuff. , Write your code as below:-
code :
$query = "SELECT * FROM Client_Information WHERE username='$myusername' and password='$mypassword'";
$result = mysql_query($query);
if (!$result) {
        // Debug query result by below code
        //echo 'Could not run query: ' . mysql_error();
        //exit;
        echo '<script language="javascript">';
        echo 'alert("Username / Password Seems Wrong !")';
        echo '</script>';
        // OR
        // echo '<div class="incorrect">- Incorrect username or password -</div>';
    }else{
       $row = mysql_fetch_row($result);
       $idClientValue = $row[0];
       if ($idClientValue == '43') {
          header("Location: admin.php");
       }
       $seconds = 5 + time();
       setcookie(loggedin, date("F jS - g:i a"), $seconds);
       header("location: login_success.php");
    }    
Rails comments and username won't show up in post views / undefined method `user' for nil:NilClass

Rails comments and username won't show up in post views / undefined method `user' for nil:NilClass


By : rgshea003
Date : March 29 2020, 07:55 AM
around this issue In the show method of your post_controller, you'll need to do something like:
code :
def show 
  @post = Post.find_by(id: params[:id]) # or however you find your post
  ....
end
<% @post.comments.each do |comment| %>
  ... show some comment stuff 
  <%= comment.user.name %>
<% end %>
Can admin username and application's user username be same?

Can admin username and application's user username be same?


By : user3429419
Date : March 29 2020, 07:55 AM
like below fixes the issue You shouldn't accept it, it can make troubleshooting more difficult later.
i.e. User wants to reset password because he forgot it. Who's password should be updated?
Django error admin.E033: username is not an attribute of users.CustomUser. Why is my custom user admin not working?

Django error admin.E033: username is not an attribute of users.CustomUser. Why is my custom user admin not working?


By : Wannes van Praet
Date : October 06 2020, 03:00 PM
hope this fix your issue Like the error says, the admin class for User by default orders by username. Since you don't have a username, you should override that:
code :
class CustomUserAdmin(BaseUserAdmin):
    ...
    ordering = ('email',)
Related Posts Related Posts :
  • An error occurred while installing nokogiri (1.6.6.2), and Bundler cannot continue
  • How to setup nested routing for a self referencing controller in Rails 4
  • middleman app it is possible to create a contact form?
  • How to refactor this piece of code
  • How can I know if a user has access to all or just some resources with Cancan?
  • How can I run a ruby class from rake file?
  • Send JSON data as post method from rails controller to a web service
  • How to test Controllers under different namespaces and why this test fails?
  • rspec expect condition OR condition
  • Page loads unnecessary queries Ruby On Rails
  • Why "bundle install" try to install outdated version of gems?
  • Rails - Customize model validation error messages but without a database
  • When to switch from cucumber to rspec in the BDD cycle for a login procedure
  • Multipart response for web service
  • How to hide Add new option in Rails Admin
  • Override CollectionProxy find method
  • Rails 4 simple_form has_many through check boxes not saving
  • ruby on rails authentication using devise gem
  • Rails iteration over arrays and hashes
  • Creating inline date_select dropdowns using simple_form and zurb foundation
  • NameError in SongsController#index uninitialized constant Song::FriendlyId
  • Rails how to improve if record exists?
  • omniauth custom request phase form
  • Rails 5 - Saving the absolute current url via a button to a cookie?
  • How can / should I override the `build` method for a my model?
  • Install Rails Failed on OSX 10.8.4
  • ruby on rails - undefined method valid?
  • Users Registration on POST
  • Rails application variables in carrierwave store_dir
  • How to customize simple_form for json nested hash
  • Couldn't find file 'jquery', Sprockets::FileNotFound in StaticPages#home error
  • How should I use the alias_method_chain for the build method?
  • how to create two custom registration forms in devise?
  • Rails 4 link_to Destroy not working in Getting Started tutorial
  • How does ruby on rails dynamically define `find_by_id`, `find_by_name` methods?
  • JBuilder dynamic keys for model attributes
  • `initialize': No such file or directory - getaddrinfo (Errno::ENOENT) when Rails new app
  • What is the Ruby equivalent of Node.js' socket.io?
  • Where rails store standard helpers?
  • how to check expected result matches any of give values in rspec?
  • Form submission to create multiple objects
  • Simple Twitter Login with Rails and Email confirmation
  • Where should helpful functions for my controller go in Rails?
  • Using session variable in the Model or the other way
  • Why can't I have ruby code and comments in Embedded Ruby?
  • Rails: How can I make an object available in all views?
  • Cannot enter simply form information into SQLite DB (Rails)
  • Rails - Retain form values on failed submission. Getting "First argument in form cannot contain nil or be empty&quo
  • How to handle STI and build related models automatically?
  • Suppress an error when saving a record in Rails
  • Rails AJAX reload the page. Why?
  • How to pass user attributes to action mailer
  • Custom Validator to Prevent an appointment from being scheduled too early in day?
  • Postgres Enable TCP/IP Connection
  • How do I avoid the circular argument reference warning in activesupport
  • Unable to push to heroku master because of rails/spring version error
  • deep nested routes in rails
  • Best approach to Users Profile Images in Rails App
  • RailsInstaller: Can I maintain the gem fold when re-installing a new version?
  • couldn't find file 'jquery-ui' i get this error even after having this file in my application.js
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org