(Saw many posts with these problems and got it working, so I will upload solution)
I'm using Ratyrate without Devise and the stars only appear after a web refresh and they do not save the previously assigned rate.
Fixed this issue with:
Specifying version in each Rating Migration (currently using ActiveRecord::Migration[5.1])
Changing Rate Controller "create" method, replacing "if user_signed_in?" with "if current_user"
Adding "post '/rate' => 'rater#create', :as => 'rate'" to routes.rb (gem should do this for you)
Adding
<%= javascript_include_tag 'ratyrate.js', "data-turbolinks-track": false %> at the bottom of show.html.erb (the view of the model you want to rate)
Hope this helps !
Related
I don`t understand this from rails 4:
<td colspan="12" id="compatibility_activities-add" >
<%= job.link_to_add t('shared.add'), :activities,:class => "right small button radius success", :data => { :target => "#activities#{job.object.person_type}_#{job.index}" } %>
</td>
where does the "link_to_add" comes from? there is no references inside the project and cant find anything on the net, there is another "link_to_remove"
this is on a list that creates new rows or deletes them dynamicaly
My second question is, does rails 4 have the way, like laters versions to do rails routes | grep some_route ??
The helper methods you mentioned seem to be provided by the gem Nested Form or some fork of it.
Check your Gemfile for the specific gem name and you can get the official documentation on GitHub or on its website.
In rails 4, you could try using rake routes or bundle exec rake routes to get the list of the routes.
I have this:
ActiveAdmin.register User do
index do
column :email
column :name
column :role
column "Last Sign In", :last_sign_in_at
column :account
column "Units" do |user|
user.units.count.to_s
end
default_actions
end
The default_actions method should create the show, edit, and delete links. It shows them but the delete link is just a link to the show action:
admin/users/1
Specifications said it should create a delete link.
Dont know why it did that. So I tried an alternative:
column "Delete" do |user|
link_to "Delete", destroy_admin_user_path(user)
end
I get this error:
undefined method `destroy_admin_user_path' for <div class="index_as_table"></div>:ActiveAdmin::Views::IndexAsTable
I even tried adding this in routes:
match "/admin/users/:id/destroy(.:format) " => "admin/users#destroy"
Still got same error.
I included this in application.html.haml:
= javascript_include_tag :all
Still same problems as above.
Thanks for response
This is a bit late but the real real reason your link wasn't working is because you didn't put the :method in your link and instead used "destroy_admin_user_path".
Try this instead:
link_to "Delete", admin_user_path(user), :method => :delete, :data => {:confirm => "Are you sure?"}
This is what works for me, with ActiveAdmin.
I had this problem when I updated the active_admin gem, so I fixed it regenerating the active_admin assets and now the destroy action works fine.
rails generate active_admin:assets
Did you check to see if the full rails.js is added to the javascript? Use firebug to inspect the link and see if it has the data-method attribute. Also inspect the HTTP headers and see if the request is made with DELETE.
If the request is not made using "DELETE" than you have a problem with your javascripts. Check rails.js for integrity and jquery integration. Additionally check your assets.
Could your provide more details about your rails version? Javascripts included in HTML source?
Try another thing, go to assets/javascripts/application.js and add
//= require jquery
to the top if you are running 3.1
Help, I've broken my Rails3 user model!
I first noticed that I could not update users from the app itself.
It appears that I also can't from the rails console.
User.save returns false.
User.create produces a record with id=nil, which is not saved to the database.
I've spent two days trying to work out what the problem is. I've taken out all my CanCan and Devise validations. I've been through the code line by line. I am stumped!
Nothing in the logs is pointing me in an obvious direction.
I commented everything out of User.rb, but no joy.
I know this is a really vague question, that's almost impossible to answer from a far.
What I'm hoping is that someone can suggest logical steps for working through this and trying to figure out what's happening.
I'm still fairly new to Rails, and keen to learn how it all works.
Thanks for your ideas!
UPDATE:
I've been digging into this for the past week. Eventually I started a new rails app from scratch and systematically moved the old app into the new app piece by piece to try and work out where the problem lies.
I've tracked it down to my custom Devise routes.
routes.rb
devise_for :users, :path_prefix => 'registration', :controllers => {:registrations => 'users/registrations'}
If i remove the :controllers line, then I can update the users name using the Devise user edit form.
However this is not a workable solution. The Devise edit form only provides name and email fields, but there are several other columns in my user model that the user needs access to . Hence the custom routing.
So I've tracked the issue this far, but I'm not sure where to look yet. I tried editing the registrations_controller to the default values, but no luck. (I even cut as pasted the code directly from the devise git repository).
def edit
super
end
def update
super
end
So I don't think the problem is the controller.
Which leaves the form itself. The form is defined as
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :multipart => true }) do |f| %>
I can't see any issue with this. And I can't think where else to look to debug this.
To recap, the edit form displays as expected, user can edit information, click update, is redirected as expected, no errors are displayed, but the edited info is not saved. The tail shows no SQL save being called.
Very stumped, and I'd appreciate any wild ideas or suggestions!
Many thanks
Try this to debug in the console:
require 'pp'
u = User.new
u.save
pp u.errors
This should give you the errors that prevent the user from being saved to the DB.
I've eventually tracked this down to a stupid oversight on my part.
In the controller I had
resource.update_attributes!(params[:resource_name])
when what I needed was
resource.update_attributes!(params[resource_name])
An edit I must have made at some point.
A self inflicted issue that took two weeks of head scratching to resolve!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'd like to implement a captcha in a Rails project for a form submission, but I'm not sure what to go with. I'm inclining towards simplicity of implemention, and reliability when in use, over it being too sophisticated, as my application doesn't require too high a level of security.
Anyone have any recommendations?
The easiest way to add a CAPTCHA to your Rails application is using Ambethia reCAPTCHA:
1. Installation:
config.gem "ambethia-recaptcha", :lib => "recaptcha/rails",
:source => "http://gems.github.com"
You can install it as a plugin, too, if you like.
2. Get a reCAPTCHA account:
You have to create a reCAPTCHA key. You can do it on the reCAPTCHA site.
3. Usage:
Use recaptcha_tags to output the necessary HTML code and then verify the input with verify_recaptcha.
4. Further reading:
Ambethia reCAPTCHA
reCAPTCHA documentation
Installation
Add the following to your GEMFILE
gem "galetahub-simple_captcha", :require => "simple_captcha"
or
gem 'galetahub-simple_captcha', :require => 'simple_captcha',
:git => 'git://github.com/galetahub/simple-captcha.git'
Then run bundle install if you're using Bundler (or use the package manager for your Rails configuration)
Setup
After installation, follow these simple steps to setup the plugin. The setup will depend on the version of rails your application is using.
rails generate simple_captcha
rake db:migrate
Usage
Controller Based
Add the following line in the file “app/controllers/application.rb”
ApplicationController < ActionController::Base
include SimpleCaptcha::ControllerHelpers
end
In the view file within the form tags add this code
<%= show_simple_captcha %>
and in the controller’s action authenticate it as
if simple_captcha_valid?
do this
else
do that
end
Model Based
In the view file within the form tags add this code
<%= show_simple_captcha(:object=>"user") %>
and in the model class add this code
class User < ActiveRecord::Base
apply_simple_captcha
end
FormBuilder helper
<%= form_for #user do |form| -%>
...
<%= form.simple_captcha :label => "Enter numbers.." %>
...
<% end -%>
Validating with captcha
NOTE: #user.valid? will still work as it should, it will not validate the captcha code.
#user.valid_with_captcha?
Saving with captcha
NOTE: #user.save will still work as it should, it will not validate the captcha code.
#user.save_with_captcha
Formtastic integration
SimpleCaptcha detects if your use Formtastic and appends
“SimpleCaptcha::CustomFormBuilder”.
<%= form.input :captcha, :as => :simple_captcha %>
Options & Examples
View Options
*label* - provides the custom text b/w the image and the text field, the default is “type the code from the image”
*object* - the name of the object of the model class, to implement the model based captcha.
*code_type* - return numeric only if set to ‘numeric’
Global options
image_style - provides the specific image style for the captcha image.
There are eight different styles available with the plugin as…
simply_blue
simply_red
simply_green
charcoal_grey
embosed_silver
all_black
distorted_black
almost_invisible
Default style is ‘simply_blue’. You can also specify ‘random’ to select the random image style.
distortion - handles the complexity of the image. The :distortion can be set to ‘low’, ‘medium’ or ‘high’. Default is ‘low’.
*Create “rails_root/config/initializers/simple_captcha.rb”*
SimpleCaptcha.setup do |sc|
# default: 100x28
sc.image_size = '120x40'
# default: 5
sc.length = 6
# default: simply_blue
# possible values:
# 'embosed_silver',
# 'simply_red',
# 'simply_green',
# 'simply_blue',
# 'distorted_black',
# 'all_black',
# 'charcoal_grey',
# 'almost_invisible'
# 'random'
sc.image_style = 'simply_green'
# default: low
# possible values: 'low', 'medium', 'high', 'random'
sc.distortion = 'medium'
end
You can add your own style:
SimpleCaptcha.setup do |sc|
sc.image_style = 'mycaptha'
sc.add_image_style('mycaptha', [
"-background '#F4F7F8'",
"-fill '#86818B'",
"-border 1",
"-bordercolor '#E0E2E3'"])
end
You can provide the path where image_magick is installed as well:
SimpleCaptcha.setup do |sc|
sc.image_magick_path = '/usr/bin' # you can check this from console by running: which convert
end
You can provide the path where should be stored tmp files. It’s usefull when you dont have acces to /tmp (default directory)
SimpleCaptcha.setup do |sc|
sc.tmp_path = '/tmp' # or somewhere in project eg. Rails.root.join('tmp/simple_captcha').to_s, make shure directory exists
end
How to change the CSS for SimpleCaptcha DOM elements?
You can change the CSS of the SimpleCaptcha DOM elements as per your need in this file.
*/app/views/simple_captcha/_simple_captcha.erb*
View’s Examples
Controller Based Example
<%= show_simple_captcha %>
<%= show_simple_captcha(:label => "human authentication") %>
Model Based Example
<%= show_simple_captcha(:object => 'user', :label => "human authentication") %>
Model Options
message - provides the custom message on failure of captcha authentication the default is “Secret Code did not match with the Image”
add_to_base - if set to true, appends the error message to the base.
Model’s Example
class User < ActiveRecord::Base
apply_simple_captcha
end
class User < ActiveRecord::Base
apply_simple_captcha :message => "The secret Image and code were different", :add_to_base => true
end
Well, ReCaptcha will do the job and there are many tutorials on it online.
However, you have to write a correct "def create" (create method) in your controller that will pass whatever is in your form plus validate Recaptcha at the same time. Then it will work nicely.
There was one little problem with it. After I inserted ReCaptcha into my form, the form validation stopped working. However, it can be fixed with an easy code inserted into the model file:
after_validation :on => :create
(:create = is the "def create" method in your controller). It will force the form to validate the form first and then validate Recaptcha.
I've used Recaptcha in one of my PHP project. http://recaptcha.net/
According to the site, it also has plugins for Ruby (http://recaptcha.net/resources.html). Although first ruby link didn't work, next link still works. http://svn.ambethia.com/pub/rails/plugins/recaptcha/
Check it.
I've used ambethia recapchat for rails application. it most easy than other
reCAPTCHA for rails is great, in terms of functionality. However, if you require XHTML validation, RUN AWAY! This plugin does not (and probably never will) validate. I find it embarrassing that only one page on my entire site does not validate - it is the page with reCAPTCHA. If there was ANY other choice, I would take it.
if you're after a CAPTCHA that validates, and is (almost) as easy to use as reCAPTCHA, please give my SlideCAPTCHA a try. (Wrote it a few days ago, needs some tests in real-life usage.) I based its deployment process on the reCAPTCHA plugin, but you can style it with CSS.
It does require Ruby/GD, however, so if you don't have GD already, I can't promise that GD is easy to install and use!
If you haven't seen my question yesterday, this is my second rails app. The first went nice and smooth, but this one keeps giving me one random error after another. I installed active_scaffold for this app as well as the last app (the first error, instead of using script/install plugin git://active_scaffold repository, I did script/install plugin http://active_scaffold repository.) I didn't want to spell out basic CRUD on minor models. After the install problems, (before I found the http solution from a windows user when I'm on Linux) I thought I'd try out Hobo. Well, Hobo updated actionmailer, actionpack, activerecord, activeresource, and installed rack. Rails isn't even using the updated versions. But as you can see at the bottom of the trace it's using rack. I have a feeling it has something to do with my futzing around with installing Hobo which I uninstalled. Thanks in advance.
[Edit]
I had asked the question over at the
ActiveScaffold Group
the answer (if you don't want to follow the link) was that this line needed to be added to routes:
map.resources :modelName, :active_scaffold => true
It doesn't entirely answer my question, since the documentation said nothing about changing routes. But, it works.
[/Edit]
ActionController::RoutingError in Departments#index
Showing vendor/plugins/active_scaffold/frontends/default/views/_list_header.html.erb where line #8 raised:
No route matches {:_method=>:get, :action=>"show_search", :controller=>"departments"}
Extracted source (around line #8):
5: <% next if controller.respond_to? link.security_method and !controller.send(link.security_method) -%>
6: <% next if link.action == 'new' && params[:nested].nil? && active_scaffold_config.list.always_show_create %>
7: <% next if link.action == 'show_search' && active_scaffold_config.list.always_show_search %>
8: <%= render_action_link(link, new_params) -%>
9: <% end -%>
10:
11: <%= loading_indicator_tag(:action => :table) %>
Trace of template inclusion: vendor/plugins/active_scaffold/frontends/default/views/list.html.erb
Full Trace It was taking forever to format it. I'm still not fully conversant in SO's formatting (sometimes the server is down. reboots are reinstalls. it's a play server)
Add this to routes:
map.resources :modelName, :active_scaffold => true
And, contrary to my edit, it is in the documentation. It's in the wiki at Github. My second question at SO, and I could have found the answer by RTFM'ing. <sigh>
For Rails 4+ at least, your entry in config/routes.rb should look like:
resources :models do # my model name in plural
as_routes
# for action links of type member, add the following
# see also [note, via the action-link API, you can change the HTTP verb. Adjust this route accordingly.
# https://github.com/activescaffold/active_scaffold/wiki/Adding-custom-actions
# get :my_custom_action, :on => :member
end
Note, getting the right version of the Gem requires the following config in your Gemfile:
gem 'active_scaffold', github: 'activescaffold/active_scaffold', :branch => "3-4-stable"
If you get an error that "as_routes" isn't found; that'd be the problem.
THIS IS RAILS 4 ONLY
For Rails 5.x you can set route as follow:
resources :model, concerns: :active_scaffold