Unable to implement recaptcha gem options in a Rails 4.2 app - recaptcha

I am using the recaptcha gem version 4.0, and therefore placed <%= recaptcha_tags %> inside a form. There are options that you are supposed to be able to implement to change the size (normal or compact?) and theme (light or dark).
I reviewed numerous posts here and elsewhere without finding a syntax that works. Here are several options I used based on what I found:
<%= recaptcha_tags :display => {:size => 'compact', :theme => 'dark'} %>
<%= recaptcha_tags :display => {size: 'compact', theme: 'dark'} %>
<%= recaptcha_tags :size => 'compact'} %>
<%= recaptcha_tags size: 'compact'} %>
Nove of these worked. I also removed the options from the recaptcha tags and modified the gem's client_helper.rb file. I cut all of the width and height styles were cut in half. That didn't work either. I'd rather use the options that can be supplied in the recaptcha tags. Anybody know how to do that? Thanks in advance! Jay

check the generated tag, if you pass size: 'compact' it should create a data-size="compact" attribute
https://github.com/ambethia/recaptcha/blob/master/lib/recaptcha/client_helper.rb#L70-L71
if that does not work, update to latest ... maybe bundle open recaptcha ... if size should not be data-size but regular size then this might be a bug and needs a proper fix ... still open the gem, turn it remove :size from the list and see if that fixes it
--retransmitted from grosser

Related

MissingTemplate Frustrating behavior

I am completing this rails tutorial
Everything was going along smoothly even though im working on windows, until i hit the partials section.
I pretty much copy pasted everything from the tutorial. I made sure that the underscore character in the partial filenames is an actual underscore.
I have placed the partials in the
app/views/layouts/
path as the tutorial suggests and included the
<%= render 'layouts/shim' %>
in my application.html.erb file. This results in the
ActionView::MissingTemplate in StaticPages#home
Showing E:/ruby/my_projects/sample_app/app/views/layouts/application.html.erb where line #9 raised:
Missing partial layouts/shim with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "E:/ruby/my_projects/sample_app/app/views"
Extracted source (around line #9):
"data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %> #this is line number 9
</head>
<body>
<%= render 'layouts/header' %>
I have tried placing the files directly in views folder as well as in the static pages folder.
I restarted the rails server multiple times during this process.
Anybody has any ideas?
Ok I guess its a ridicules mistake but it took me so long to figure it out. It should be obvious for me that windows hides extensions so after i misnamed my file the first time and tried to fix it (rename it) it already hid the .erb extension. So it had an .erb.erb extension and because of that it didnt work.
Thanks everyone that tried to help.

Rails, Twitter Bootstrap, Simple Form, Heroku - Odd error when using ":wrapper => :prepend do" to get an add-on span

I have the following code in a form partial:
<%= f.association :client %>
<%= f.input :url, :wrapper => :prepend do %>
<%= content_tag :span, "http://www.", :class => "add-on" %>
<%= f.input_field :url, :class => 'span4' %>
<% end %>
Trying to load anything to do with this form partial e.g. new/edit etc causes Heroku to error. It works flawlessly on localhost.
The only obvious error in the Heroku logs is:
ActionView::Template::Error (undefined method `source' for nil:NilClass):
I'm afraid I don't really understand that but thought it might help anyone trying to answer this.
If I change the form partial code it works on Heroku no problem at all e.g.
<%= f.input :url, :input_html => {:class => 'span4' } %>
Obviously I lose my nice bootstrap add-on span so I'd rather find out what the issue is rather than running around it.
Shot in the dark, but maybe an initializer that sets up the prepend wrapper (like initializers/simple_form.rb or initializers/simple_form_bootstrap.rb) is not being run by Heroku, either because it's not checked into git, or because of some environment-specific logic in the initializers or environment files.
Well after testing and some help from Dan I finally got to the bottom of it. Unfortunately, it seems to be quite localised to my situation though.
But just in case anyone stumbles across this, the error I had was the following:
ActionView::Template::Error (undefined method `source' for nil:NilClass):
That was in the log and was THE SAME when I followed Dan's advise to turn on error reporting on the production site (set consider_all_requests_local = true in config/environments/production.rb).
I thought that the error was being caused in the template, however, it was some validation rules in the model. The validation rules for me where some regex to stop the user starting the input with a certain string. They worked perfectly fine on my local, but Heroku really wasn't liking it!
I removed those validation rules and voila, my nice bootstrap add-on span was working perfectly.

Remote Method Understanding?

In rails 3
While using remote method form submit, it affects the database twice with the same form values.
controller file:
#user_message = UserMessage.new(params[:user_message])
if #user_message.save
render :update
else
render :nothing => true
end
view file:
<%= form_tag ('/feedback/user_message'), :method =>'post', :remote=> true, :id=>'user_message' do%>
<%= hidden_field_tag 'user_message[user_id]', #user.user_id %>
<h2><%= #question %></h2>
<%= text_area_tag 'user_message[msg]',"", :size=>"40x5" %>
<%= submit_tag "Submit"%>
<% end %>
When I hit the submit button it creates two records on the table.
Why?
There may be couple of things that might be causing this
may be the ujs file is included twice may may be like
//= require jquery_ujs // expected to load from the rails-jquery gem
//= require_tree . // if any file is present in assets directory hierarchy it will be loaded
Or just a bug taking your sleep away
https://github.com/rails/jquery-ujs/issues/208
check out more solutions
Jquery Rails 3... form submits twice... deletes twice... help
Rails 3.1 remote requests submitting twice
This may also be related to the understanding of asset pipeline when and how use pecompiled assets.
I always use this config in development mode
config.server_static_assets = false
this forces the app to call the assets from app assets
and use precompiled assets from public in production mode
The problem most likely related to asset pipeline
You should precompiled the asset pipeline before.
This will create two copy of rails.js, one in your assets and one in application.js
This is a bug or gotcha in rails 3
See here http://www.ruby.code-experiments.com/blog/2011/10/another-gotcha-with-the-rails-31-asset-pipeline-or-why-are-my-jquery-ujs-ajax-requests-triggered-twi.html
Hope this help

Rails 3.1 Devise How To Change Flash Message CSS From notice to success?

Rails 3.1 and Devise 1.5 question.
I'm using the following code to display flash messages in my layout:
<% flash.each do |key, message| %>
<%= content_tag(:div, message, :class => "flash #{key}") %>
<% end %>
I'd like to change the css class for some of my confirmation messages from notice to success, but I don't know where to override or change the key because I don't know where it's set.
Can anybody point me in the right direction?
Thanks!
So the way to do this is to edit the devise controllers.
When you install Devise through the normal installation I don't think it install the controllers (at least it didn't for me).
So first you should manually add the controller files and put them into your project in the same location: https://github.com/plataformatec/devise/tree/master/app/controllers/devise
Once you have the files in your project, go to the "sessions_controller.rb" file.
One lines 16 & 25, you should see the code:
set_flash_message :notice, :signed_in
and
set_flash_message :notice, :signed_out
You just need to change ":notice" to ":success"
Hope that works!
I ran into this problem because I'm using the bootstrap-sass gem which uses a whole different class structure for flash messages. I took the route of solving this with sass rather than messing with devise at all (sass inheritance is awesome:).
So, I render the flash messages in app/view/layouts/application.html.haml:
%div.container
- flash.each do |key, value|
= content_tag(:div, value, class: "alert alert-dismisable alert-#{key}")
And, I add a simple rule to app/assets/stylesheets/custom.css.scss to get Devise's flash messages working:
/* Style Devise Flash messages like Bootstrap */
.alert-alert {
#extend .alert-warning;
}
That's it! now flash[:alert] is styled just like bootstrap's flash[:warning].
The css class is being set by the :class argument. To add a class of notice (or success, etc.), just change your call to the following:
<%= content_tag(:div, message, :class => "flash #{key} notice") %>

ArgumentError (2 for 1):Rails3.1.0 <%= stylesheet_link_tag "application" %>

wrong number of arguments (2 for 1)
Extracted source (around line #5):
<html>
<head>
<title>Assets</title>
<%= stylesheet_link_tag 'application'%>
<%= javascript_include_tag %>
<%= csrf_meta_tags %>
</head>
I've tried:
<%= stylesheet_link_tag :all %>
but I got:
<link href='assets/all.css' ...>
What confused me most is that I run an app on my MAC OS with almost the same config except mysql&Gemfile and it works well, but when I turn to centos5 I got these errors!
I had this problem too, and it turned out to be due to some code still targeting an older rails version, before the new asset pipeline work. Specifically, I had a redmine plugin using the method image_path with two arguments:
image_path('database_refresh.png', :plugin => 'redmine_rate')
This was no longer possible, and needed to be replaced with code that explicitly calculated the plugin specific path. I used code based on the wiki document at http://www.redmine.org/boards/3/topics/31445#Links-and-paths-to-plugin-assets
Note that this solution was for a problem I had with redmine, not rails, but could in fact be relevant.
<%= stylesheet_link_tag "application" %>
Should be fine. Rails has an assets pipeline to merges all the different stylesheets into one for the productive environment. I think it is an error in the assets pipeline.
Here is a good tutorial about this pipeline:
http://railscasts.com/episodes/279-understanding-the-asset-pipeline
To possibly fix your error have a look at config/environments/production.rb and try to set this to true
config.assets.compile = true
Another problem might be the configuration in the application.css have you perhaps deleted the comments or added something?
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require_tree .
*/
But these are just guesses... but I hope this leads you towards the solution of the problem.

Resources