Rails, Formtastic - model name not showing on form buttons - ruby-on-rails

I have just deployed an existing app to a new server and have noticed that where model names are automatically generated (by Formtastic) it instead outputs {{model}} rather than the expected name.
For example, in the linked image it should read 'Create Category' but instead reads 'Create {{model}}'
https://skitch.com/simon180/rr4w9/example
I don't know where to start in figuring what causes this.
Rails version is 2.3.5 (vendored) and gems vendored too.
Any suggestions gratefully received!
Thanks
Simon

Have a look in the formtastic gem, depending on what version you have, the file will be
/lib/formtastic/i18n.rb
or
formtastic/lib/locale/en.yml
it should have something like this:
'Create %{model}'
but yours will have:
'Create {{model}}'
Thats the old format. Change occurrences of {{foo}} to %{foo}
or
Updating the formtastic gem should do the trick

Another option is to downgrade the i18n gem to 0.4.1 this problem will disappear.
The problem is with the i18n gem version. From version 0.4.1 on, the way of accessing variables isn't {{variable}} anymore.

Related

How to upgrade Administrate gem

I have a Rails 4 app with Thoughtbot Administrate for the admin part.
Recently I tried to upgrade from version 0.1.2 to 0.1.4, but I got this error: cannot load such file -- administrate/fields/base.
It was triggered from a custom field file, so I tried to run rails g administrate:install, which asked me to overwrite all my administrate controllers and dashboards.
Now, I have made customizations to those files, so I opted not to overwrite them, but then I ended up with the same error as before.
Next, I made another branch to test and let administrate to overwrite my controllers and dashboards, and this time it worked!
So, I think the question is, what is the process to upgrade the gem without losing my customizations?
Is there any task I can run in order to "register" the updated gem, like rake administrate:upgrade or so?
Thanks!
Found out the error.
Seems that administrate/fields/base is now administrate/field/base, so this subtle update in the Administrate gem code is breaking my custom field.
Anyway, I think a potentially breaking update to the gem's code should be advertised and maybe even change the mayor version number, so I'll rise an issue in github for this one.

undefined method `boolean_label_class=' for SimpleForm

Attempting to run migration for my Rails app pixel_paisan is getting an error reading; NoMethodError: undefined method `boolean_label_class=' for SimpleForm:Module. Gist for the trace at https://gist.github.com/nbarnes/9796454dc28be9792284. Source code for error-production app at https://github.com/nbarnes/pixel_paisan.
I've tried uninstalling and reinstalling simple_form, doesn't help. Update entire gemset, doesn't help. Different ruby versions via RVM, doesn't help. Plain vanilla Rails app, created in an attempt to reproduce the bug works fine. Google doesn't know about my issue.
Does anybody know anything about this? I'm rapidly running out of angles to attack it from.
Short answer: update your simple_form gem to 3.1.0+. You have simple_form (3.0.2)
Longer answer: See https://github.com/rafaelfranca/simple_form-bootstrap/issues/44 which seems to be someone who had the same issue where the answer is to upgrade to simple_form 3.1.0+ whereas your Gemfile has simple_form (3.0.2)

I18n strange behaviour

I am using I18n with Redis store, and have a strange behavior after updating to Rails 3.2.13
[6] pry(main)> I18n.t("my_website_field")
=> "M"
[7] pry(main)> $redis.get("en.my_website_field")
=> "\"My website\""
I am getting only the first letters of the translations
To my knowledge I believe that redis-store has issues with certain versions of Rails (3.2.13 happens to be one of those).
Since I was really curious about why this would be happening I opened up the Github change log and took a look at the logic they changed in the 3.2.12 -> 3.2.13 update.
The main change that I noticed was the dependency chain in ActiveSupport for i18n.
The code was changed FROM
s.add_dependency('i18n', '~> 0.6')
TO
s.add_dependency('i18n', '= 0.6.1')
The only other changes were (from the changelog):
Add i18n scope to `distance_of_time_in_words
So if I had to take an educated guess I would say that the forcing of the use of i18n to 0.6.1 created some type of conflict with redis-store.
Note: I will continue to look into the issue with the change logs to i18n and post if I have any more information on the subject.
Can't find the specific issue in commit history and they don't keep a changelog (havent for 3 years :/) but I'd be curious to see if forcing the old version control would allow i18n to function properly.

What's your solution for 'contact forms' in Ruby on Rails applications?

With a quick Google search, one can find literally hundreds of examples for contact forms using PHP and/or JavaScript, but there don't seem to be any "ready-made" contact forms for Ruby on Rails. Do they exist? What do you use for contact forms in your Ruby on Rails apps?
Personally, I use an ActiveRecord model for mine as I like to keep a store of messages being sent, and then use an ActionMailer after saving a record to send an email.
Alternatively there is a gem called MailForm which allows you to build a form model without a database table, which will work with other gems such as Formtastic.
As for ready-made contact forms, I don't know of any (though they may well exist) as it's not particularly time-consuming to build one from scratch.
I was running into the same issue with wanting an easy to use out of the box Contact Form, but wasn't able to find one. So I've written ContactUs a Rails Engine that you can easily drop into any Rails 3+ application. I tried to keep it dead simple and as easily configurable as possible. It does require the Formtastic gem since I wanted an easy way to hook into peoples existing form styles though.
To install the Engine add the contact_us gem to your Gemfile:
gem 'contact_us', '~> 0.1.3'
Run bundle and the install rake task:
$ bundle
$ bundle exec rake contact_us:install
Then just modify the generated initializer in /config/initializers/contact_us.rb to have the email you want the form submissions sent to.

rails plugin installation and upgrades

I have a rails plugin written in v 2.1.1. When I install it in a 2.2.2 app, it breaks the app. I'm unable to use polymorphic routes so something like
<%= link_to #object %>
Doesn't work, because it says:
ActionView::TemplateError (undefined method 'polymorphic_path' for #<ActionView::Base:0x1a95c1c>)
If I script/plugin remove the plugin, it's still broken. So I have a two part question:
What is script/plugin install doing besides just copying the files into vender/plugins. From the output after installing it, it just looks like it's copying the files over, but clearly something else is going on behind the scenes, because removing it doesn't fix the problem
What do I need to do to update this plugin for rails 2.2.2. I don't know much about plugins, but I don't see anything that has specific version code in the plugin itself, so I can't figure out what exactly is breaking and what needs to be updated. Obviously this one is kind of tough to answer without seeing the code, but it's not actually the code in the plugin that's breaking, it's the plugin that is affecting my whole rails config.
Does anyone have experience with upgrading plugins to work for newer versions of rails?
Turns out the plugin was overwriting the RouteSet::draw method and just needed to be updated to the 2.2.2 draw code :P

Resources