Posts

Showing posts with the label Ruby On Rails 3

Adding A Column To An Existing Table In A Rails Migration

Answer : If you have already run your original migration (before editing it), then you need to generate a new migration ( rails generate migration add_email_to_users email:string will do the trick). It will create a migration file containing line: add_column :users, email, string Then do a rake db:migrate and it'll run the new migration, creating the new column. If you have not yet run the original migration you can just edit it, like you're trying to do. Your migration code is almost perfect: you just need to remove the add_column line completely (that code is trying to add a column to a table, before the table has been created, and your table creation code has already been updated to include a t.string :email anyway). Use this command at rails console rails generate migration add_fieldname_to_tablename fieldname:string and rake db:migrate to run this migration Sometimes rails generate migration add_email_to_users email:string produces a migration like th...

Active Admin Action Item/member Action

Answer : This can be done with the following: ActiveAdmin.register Post do index do column :name actions defaults: true do |post| link_to 'Archive', archive_admin_post_path(post) end end end Note that using defaults: true will append your custom actions to active admin default actions. For the friend who landed the page, In order to append more than 1 link Do Something Like: actions default: true do |model| [ link_to('Option 1', "#"), ' ', link_to('Option 2', "#") ].reduce(:+).html_safe end Found an answer here. You can do it using the below code with the code from the question (removing the action item block) index do ... actions do |subscription| link_to('Approve', approve_admin_subscription_path(subscription)) end ... end But I think there is a way to do it by appending an action to the default actions (so if you kn...

Can I Use Font-awesome Icons On Emails

Answer : You can't use webfonts reliably in html emails. Some clients might respect and render them, but the majority don't. You can use this website to convert the icons into images, and then simply download the images and upload them to Imgur. From there you can use <img> tags to link to the Imgur images. Edit: A better solution would be to host the images on your own server with the same domain as your email's domain . This will increase the chance of images automatically being displayed on your emails, as they are normally hidden until the user decides to view them. For example, if I used myname@mydomain.com to send emails, I'd host the images on mydomain.com You can embed them as images in your email. You can use fa2png.io which converts the font awesome icons to png of required size as well as color.

Can I Pass Default Value To Rails Generate Migration?

Answer : You can't: https://guides.rubyonrails.org/active_record_migrations.html#column-modifiers null and default cannot be specified via command line. The only solution is to modify the migration after it's generated. It was the case in Rails 3, still the case in Rails 6 Rails migration generator does not handle default values, but after generation of migration file you should update migration file with following code add_column :users, :disabled, :boolean, default: false you can also see this link - http://api.rubyonrails.org/classes/ActiveRecord/Migration.html Default migration generator in Rails does not handle default values, there is no way around as of now to specify default value defined through terminal in rails migration. you would like to follow below steps in order to achieve what you want 1). Execute $ rails generate migration add_disabled_to_users disabled:boolean 2). Set the new column value to TRUE/FALSE by editing the new migration file cr...