Before I go roll my own and start pulling out the dictionary, does anyone know a rubygem to generate memorable names suitable for app keys. I need something pronounceable so that I can give users unique email addresses to submit content to. I like Heroku's naming for it's apps as an example.
floating-sky-58
simple-fog-45
I just did an implementation of this for a project and my solution was to use the Forgery gem and something like this:
[Forgery::Basic.color, Forgery::Address.street_name.split(" ").first, rand(100)].join("-").downcase
This results in strings like this:
=> "orange-nobel-93"
=> "indigo-holmberg-41"
=> "khaki-sunfield-31"
=> "goldenrod-warrior-92"
=> "fuscia-manley-75"
=> "violet-village-17"
=> "violet-west-11"
=> "goldenrod-oak-74"
=> "yellow-hermina-74"
=> "red-shopko-36"
=> "purple-esch-43"
=> "teal-sutherland-44"
=> "blue-butterfield-56"
=> "yellow-mcbride-41"
You can use randexp gem. It's use the dictionnary from your OS ( UNIX only )
with randexp gem you can do something like :
/[:word:]-[:word:]-\d+/.gen
and have like heroku naming.
If your server has no dict library install you can try faker or Lorem
but really much limitated.
Take a look at my gem, does exactly this
gem 'bazaar'
Bazaar.heroku
=> "inquisitive-cavern-6617"
=> "jubilant-sunset-9301"
=> "frightened-geyser-4542"
https://rubygems.org/gems/bazaar
The haikunator gem is a good choice.
Related
I have such code of searching (with metasearch rails gem):
#pre_oils = Oil.search({:manufacturer_like => params[:oilbrand], :description_like => params[:oiloiliness], :description_like => params[:oilstructure], :capacity_eq => params[:oilsize]})
But i must to search via description with like on two params: oiloiliness, oilstructure... In some cases i could have first, but didn'r have oilstructure or have oilstructure but didn't have oiloiliness...
if i leave
#pre_oils = Oil.search({:manufacturer_like => params[:oilbrand], :description_like => params[:oiloiliness], :capacity_eq => params[:oilsize]})
all is ok
Now it is not searching via oiloiliness, but why ? How to do it? How to search via both fields?
I recently came across sending emails via Rails. After watching railcast, it seems that you can write up a template when using Action Mailer. I really liked this feature for my purpose. I also came across Pony, which seems really easy to use.
I was wondering if I can use templates for sending emails via Pony, unless Pony is meant for express non-templated emails.
You can easily access the view framework by explicitly rendering a template:
Pony.mail(
:to => 'somewhere#example.com',
:from => 'sender#other.example.com',
:subject => 'an example',
:body => render_to_string("path/to/_partial", :locals => {foo: #foo}, :layout => false)
)
In my research, Pony seems to be promoted as a non-template based tool, making it "simpler" to use. The home page for the utility does not mention templates at all:
https://github.com/benprew/pony
I'm trying to use active scaffold(3.0.26) in my Rails (3.0, ruby 1.8.7) project. I've added a simple tender to my page:
<%= render :active_scaffold => 'users', :constraints => {:gender => "male"}%>
When I enter that page, application starts an infinite loop. consumes more and more resources and the only solution is to kill -9 the server process. It feels like a basic mistake, but I don't know, what I did wrong. Could you help me?
Please don't use Active Scaffold. It's a really old and buggy project. I would recommend the use of rails_admin instead.
Hi I have read all the other post relating to this but I think I am missing something fundamental. I am using mini_fb in my ruby on rails application for handling the facebook api. I have the following code:
current_user.session.post('me', :type => :feed, :params => {:name => "name",
:to => "{\"data\":[{\"name\":\"#{friend.facebook_name}\",\"id\":\"#{friend.facebook_id}\"}]}",
:link => url_of_app,
:description => "desc",
:actions => "{\"name\": \"action name\", \"link\": \"url\"}"})
The above posts to the current user's wall with or without the "to" parameter set. Everything works, except for the "to" parameter. I have read the graph post to wall over and over again and I can't figure out what is wrong with this code of mine. I would really appreciate it if someone could point out my mistake.
I've never used ruby's version, but probably the problem is in the first parameter. You are targeting 'me' feed, while should be targeting your friends feed. Try fetching your friend id and doing something like
current_user.session.post(friend.facebook_id, :type => :feed, :params => ...)
Wow, mini_fb looks so verbose :)
Telémako is right, you need to use your friends id. I give you another alternative for more nice code. Use Koala.
https://github.com/arsduo/koala/wiki/Graph-API
#graph.put_wall_post("explodingdog!", {:name => "i love loving you", :link => "http://www.explodingdog.com/title/ilovelovingyou.html"}, "tmiley")
=> {"id"=>"83901496_520908898070"}
I use it in my projects and works very well.
I'm running into an issue with different users uploading files with the same name being overwritten with the Polymorphic Paperclip plugin. What I'd like to do is inject the current user's ID into the URL/path. Is this possible? Would I be better off generating a random name?
Here are my current :url and :path parameter values in asset.rb:
:url => "/assets/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/:id/:style/:basename.:extension"
What I'd like to be able to do is this:
:url => "/assets/#{current_users_id}/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/#{current_users_id}/:id/:style/:basename.:extension"
Use Paperclip interpolations:
file config/initializers/paperclip.rb:
module Paperclip
module Interpolations
def user_id(attachment, style)
current_user.id
end
end
end
has_ attached_file option:
:url => "/assets/:user_id/:id/:style/:filename"
(The syntax changed from Paperclip 2.x to 2.3; :path is not necessary; Use the latest version and have a look at the source, it's quite well documented.)
Every time I see the word random and it relates to strings, I think GUID. Perhaps they could work for you.
for me it didnt work bypaperclip.rb but it works like this:
In the model class:
class Micropost < ApplicationRecord
Paperclip.interpolates :user_id do |attachment, style|
attachment.instance.user_id
end
has_attached_file :pic1,
:url => "/Microposts/:user_id/:style/:basename.:extension"
In case if you want to do it by Paperclip interpolations you should find a path like this:
first find gem file path. type this in your terminal:
$ gem env
Then, it will show you a path in "- GEM PATHS:"
in my case this was the path :
:/usr/local/lib/ruby/gems/2.4.0/gems/paperclip-5.0.0/lib/paperclip
In this direction you can find "paperclip.rb" .