spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » RUBY ON RAILS » Page 1
How do I group and sort by a nested attribute in rails?
You can do group_by and it will convert it to array, but you can then sort array with sort_by method that exist in an Array class. class BillableEventController < ApplicationController def invoice @billable_jobs = @billable_event.billable_jobs # group records by customer customers = @billable_jobs.group_by{|e| e.job.customer} # when you call group_by it creates array # [&

Categories : Ruby On Rails

How do I redirect users to a different path upon signing in? (with Devise)
Look a little harder :) https://github.com/plataformatec/devise/wiki/How-To:-redirect-to-a-specific-page-on-successful-sign-in In your ApplicationController def after_sign_in_path_for(resource) user_dashboard_path end

Categories : Ruby On Rails

I cannot edit a field with mechanize
The problem may be that you didn't change hidden control readonly attr. From Mechanize FAQ: How do I change INPUT TYPE=HIDDEN field values (for example, to emulate the effect of JavaScript code)? As with any control, set the control’s readonly attribute false. form.find_control("foo").readonly = False # allow changing .value of control foo form.set_all_readonly(False) # allow changing the .va

Categories : Ruby On Rails

Parsing icaldav events matching a time range
Did you have a look at this Gem instead ? https://github.com/n8vision/caldav-icloud It seems more up to date than the gem you're using. And the ability to find events within time interval may speed up the query a lot.

Categories : Ruby On Rails

How to get the average colors used in a photo with RMagick in Rails?
If you want to get the one average color of any image, just scale it to a size of 1x1 pixels. The color of that pixel will be the avarage color of the original image. You can do this in a single step by outputting to txt:-: convert image -scale 1x1 txt:- Examples: convert rose: -scale 1x1 txt:- # ImageMagick pixel enumeration: 1,1,255,srgb 0,0: (146,89,80) #925950 srgb(146,89,80) Th

Categories : Ruby On Rails

Active Admin: two nested forms for two objects of the same class
At first, my intention is to share something available on active admin which might works in your case. But as I am not so much confident about your question, can you please review my answer and let me know if this helps ? ActiveAdmin.register Post do form do |f| ....... f.inputs do f.has_many :some_relation_one, :allow_destroy => true, as: :uniq_name ,:heading => 'Themes', :new_rec

Categories : Ruby On Rails

Why my PassBook isn't valid or outdate?
According to the Expiration Keys in the Passbook Package Format Reference check the expirationDate and voided keys. Since you do not have those in your JSON, it might be added by the gem you are using.

Categories : Ruby On Rails

heroku pgbackups:restore not working on rails app
I tested this on a blank hobby dev database with heroku. You don't need to include the the no-owner and no-acl options (-x -O) but it's considered good practice since those alter statements will fail. The problem with your dump command is the stray > pg_dump -F c -v -O -x -U john -h localhost project_development -f dumpfile.dump Upload the resulting file to dropbox or s3 and try the restore

Categories : Ruby On Rails

Rails nested joins with a has_many through relationship
Thanks Everyone. Using Ave's explanation, I changed the reference names, and then updated everything else accordingly. After that I was able to run the query with @answers = Answer.joins(knowledge_topic: :student_learning_outcomes) .select( 'student_learning_outcomes.id As student_learning_outcomes_id', :is_correct, "count(answers.id) AS total_answers") .group('student_learning_outcomes

Categories : Ruby On Rails

Multiple Devise users or one user and permissions with CanCanCan?
Use only one user and assign a role to the user with a specific column like role_id. Then you can have different roles, each one with a different id. admin = 1 standard = 2 You can then define a method in the user like: def admin? role_id == 1 end and in cancan you can use it like that: def initialize(user) HERE PERMISSIONS FOR NON LOGGED USERS if user HERE PERMISSIONS FO

Categories : Ruby On Rails

Hash and frequency of a value
To find host value with highest frequency do: hs = hash.values.group_by { |h| h[:host] =~ /host.(d+)/ && $1.to_i || 0 }.to_a hs.reduce([-1,0]) { |sum,v| v[1].size > sum[1] && [ v[0], v[1].size ] || sum }.first Description: [-1,0] is the default value for set for #reduce method, where -1 is a number (like in host.number), and 0 is a count of the number. So, when reduce encount

Categories : Ruby On Rails

sunspot search on a has many association
You are not actually searching in the skill_ids field you have indexed. You must add something like: User.search do fulltext params[:free_text] #<-- YOU DON'T NEED THIS, PROBABLY? with(:skill_ids, params[:s_skills]) if params[:s_skills] end

Categories : Ruby On Rails

Using Delayed Paperclip With S3 Direct Upload
My approach was wonky.Even if it had worked it wouldn't have added the image_processing attribute to the Photo model. After digging into the Delayed Paperclip API, the following seems to have done the trick: Inside PhotosController#create: # Ensure we are flagged as processing @media_item.photo.prepare_enqueueing_for(:image) if @media_item.save # Add Job @media_item.photo.enqueue_delayed

Categories : Ruby On Rails

sendmail with RoR: not receiving mails
When i need to send a email when testing an rails app do i all ways use this code inside the development file. Then just fill it out with your gmail credentials. The rails app will then send the email through gmail with your gmail account. config/environments/development.rb config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_se

Categories : Ruby On Rails

Search within a Hash containing hashes
I saw what you have a space after the value of :method key, so try regexp to match it, like follows: hs = hash.select {|k, h| h[:method] =~ /POST/ && h[:path] == '/api/customer/191023' } To find host value with highest frequency do: hs = hash.values.group_by { |h| h[:host] =~ /host.(d+)/ && $1.to_i || 0 }.to_a hs.reduce([-1,0]) { |sum,v| v[1].size > sum[1] && [ v[0],

Categories : Ruby On Rails

time_field is not working in firefox
Yes, FireFox doesn't support all HTML 5 features. For example FireFox 19 doesn't support the date/time field. Check here compatibility of your various browser versions which are supported date/time field. http://caniuse.com/#feat=input-datetime So, update your firefox browser and it will solved your issue. ;) OR You can use Javascript or Jquery UI which will also solve your issue.

Categories : Ruby On Rails

Sass or Foundation Error after updating Rails and other gems
I found a solution. Here is what I did for anyone else experiencing this problem: Downgraded foundation-rails gem to version 5.1.1.0 (this was my original version) at this point my rails server would not start properly. Then updated foundation-rails to version 5.3.0.0 I'm not sure if there was just a gem version compatibility issue or if the downgrade/upgrade made the difference. Anyway, now

Categories : Ruby On Rails

Associating custom model with Spree
You would need a new join model such as ServiceTaxons instead of adding a service_id to Spree::Taxon. If you look at how Products are linked to Taxons it's through the spree_product_taxons table. The more important part is whether or not you need a new Service class. You would be better off having your services as just products. Products are deeply ingrained into the Spree system that you are cre

Categories : Ruby On Rails

Translate controller action_name in Rails 4
First of all, when you say #{controller.controller_name} it means that you have an object called controller accessible from your view, which is not true. Even if you manage to access the controller and the name of its action I don't think it's worth the effort and time. Instead, you can structure your translation file somehow like this: views: model_name (parkings): "Parkings" action_1_na

Categories : Ruby On Rails

How to compare new data with existing in bd before save
I believe you shall use active record's private method #read_attribute to compare current updated values with stores ones: if send(:read_attribute, :attr) == self.attr # value isn't changed end Additional info you can read here: Validation from controller You shall validate newly created record from controller: v['name'] = 'User 1' user = User.create(name: v['name']) user.name # => # Us

Categories : Ruby On Rails

Can a Drupal based website's schema be imported to Rails?
Well, I don't have straight forward answers, but I have some ideas what I would do simply to not make so much changes in the database, or as per the comment you can write down an sql script to migrate the data according to the rails schema like types for each tables. Now, I am just intended here to share my thoughts, but I believe there might be more explicit solutions and this is do-able in many

Categories : Ruby On Rails

gem for Rails log rotation and upload old logs to s3 bucket
One solution is to use one of these solutions Ruby on Rails production log rotation and then just have rake task task that would move old logs to S3 bucket rake task will be triggered by crone every night

Categories : Ruby On Rails

Removed sqlite gem but Heroku still detects sqlite gem and fails
It may be occur due to when you installed sqlite3 gem it's version details would be stored in Gemfile.lock so remove this file, don't bother of it as it will be again generated without having any source of sqlite3 gem when you run bundle install then after try to deploy on heroku

Categories : Ruby On Rails

How to Integrate Aptana studio with Bitnami Ruby Stack
You are not missing anything. There isn't an integration. Just set the workspace for aptana to the projects folder and don't use the terminal on aptana studio Just use the use_ruby.bat for terminal commands. I know senseless to actually have an IDE as nothing but a text editor but trust me you start integrating crap up the dependancy issues will ruin your life.

Categories : Ruby On Rails

Error with Bundle Install for Ruby on Rails
I think you should check if bundler is installed by using $gem list bundler or even $which bundle If nothing is shown, then install bundler by typing gem install bundler After that try bundle install

Categories : Ruby On Rails

See sent request with rest client
Check rest client logging in docs To enable logging you can set RestClient.log with a ruby Logger or set an environment variable to avoid modifying the code (in this case you can use a file name, “stdout” or “stderr”): $ RESTCLIENT_LOG=stdout path/to/my/program

Categories : Ruby On Rails

don't work checkbox "remember me" in "Log in" form
I'm following the same tutorial (I'm at the end of Ch9). I see that you gave a snipped of what you said is part of session_helper.rb but my matching code for test "current_user returns right user when session is nil" is located in testhelperssessions_helper_test.rb. Do you mind posting the full contents of that file? Here's a snippet of the first 8 lines of that file (everything minus the actua

Categories : Ruby On Rails

Limit and offset on join
This error is due to the duplication of column names in the select clause. You must specify table_name.column_name in where clause like Partner.select("addresses.*, partners.*").joins(:address).where('table_name.existing=1').page(1)

Categories : Ruby On Rails

Resource nesting in Active admin 1.x.x for Ruby on Rails
Hello Please use nested belongs_to Support nested belongs_to #376 ActiveAdmin.register FavoriteStores do controller do nested_belongs_to :users end menu false end Please also check your routes outside defined in config/routes.rb. Hope this will work :)

Categories : Ruby On Rails

Heroku exception
It looks you try to restart server, but get a fatal error. [2014-11-25 08:27:07] FATAL SignalException: SIGTERM If your server works well before, try to restart server or contact your server administrator. Heroku use Postgresql as database server, could you paste your migration here?

Categories : Ruby On Rails

Order by last name
Try this: User.select("users.*, SUBSTRING_INDEX(users.name, ' ', -1) AS lastname").limit(10).order('lastname ASC') SUBSTRING_INDEX is one of the mySQL string functions. For PostgreSQL split_part should work: User.select("users.*, split_part(users.name, ' ', 3) AS lastname").limit(10).order('lastname ASC') I am not sure, though try with -1 too: User.select("users.*, split_part(users.name,

Categories : Ruby On Rails

Ruby on Rails rooting error
you nested the route, so it should be '/api/v1/product` if you run rake routes from your console, you will get a list of all available routes. for more information about routing and nested routes, have a look at rails guides

Categories : Ruby On Rails

Mailboxer Rails 4
Hello Please use latest version of mailboxer. It works with Rails 4.0, 4.1 also. IF you still facing errors , please describe here. Thank you Mailboxer-app

Categories : Ruby On Rails

Custom error messages in rails 3
See the docs for examples: validates :user_name, uniqueness: { message: "Must to be unique" }

Categories : Ruby On Rails

Validation failed: Email can't be blank, Password can't be blank - Not Blank
Like the dump of the parameters show, the hash for the values you're after are nested within "add_clients": "add_clients"=>{ "name"=>"test 3", "email"=>"testform3@gmail.com", ... } So to get the value of, say, email, the code would be params[:add_clients][:email] etc. However I would also checkout the documentation on Strong Parameters as well as how to organise RESTful rout

Categories : Ruby On Rails

rbenv Your Ruby version is 2.0.0, but your Gemfile specified 2.1.2 but the only version installed is 2.1.2
You just need to install Ruby 2.1.2. You can have multiple Ruby versions installed at the same time. If you have ruby-build installed you can do the following: install 2.1.2, rehash your shims, and then tell rbenv to use 2.1.2 for this project. rbenv install 2.1.2 rbenv rehash rbenv local 2.1.2 You're going to have to gem install bundler and then bundle install on your project afterwards.

Categories : Ruby On Rails

How to add an admin restriction feature through Devise to my rails app?
Devise is for Authentication, your problem is an Authorization problem which Devise cannot help. You can look into Cancan https://github.com/ryanb/cancan :)

Categories : Ruby On Rails

rails 4 routes error with new controller
I'm not sure if this will fix everything, but link_to takes the anchor text as the first param. So rather than link_to organic_path, it should be link_to 'click here', organic_path or similar.

Categories : Ruby On Rails

Rails undefined method for Module
if you include MyModule into MyController, all the "instance methods" of the first will be mixed-in into the 2nd. So if you only want to call MyModule.a_method, no need to include your module. Then you'd want to require (or better autoload) your module before using it. To do so place it in controllers/concerns/my_module.rb, rails (4 at least) should autoload it, otherwise require its file in an

Categories : Ruby On Rails


Recently Add
Modelling file import using Cucumber
How do I group and sort by a nested attribute in rails?
How do I redirect users to a different path upon signing in? (with Devise)
I cannot edit a field with mechanize
Parsing icaldav events matching a time range
How to get the average colors used in a photo with RMagick in Rails?
Active Admin: two nested forms for two objects of the same class
Why my PassBook isn't valid or outdate?
heroku pgbackups:restore not working on rails app
Rails nested joins with a has_many through relationship
Multiple Devise users or one user and permissions with CanCanCan?
Hash and frequency of a value
sunspot search on a has many association
Using Delayed Paperclip With S3 Direct Upload
sendmail with RoR: not receiving mails
Search within a Hash containing hashes
time_field is not working in firefox
Sass or Foundation Error after updating Rails and other gems
Associating custom model with Spree
Translate controller action_name in Rails 4
How to compare new data with existing in bd before save
Can a Drupal based website's schema be imported to Rails?
gem for Rails log rotation and upload old logs to s3 bucket
Removed sqlite gem but Heroku still detects sqlite gem and fails
How to Integrate Aptana studio with Bitnami Ruby Stack
Error with Bundle Install for Ruby on Rails
See sent request with rest client
don't work checkbox "remember me" in "Log in" form
Limit and offset on join
Resource nesting in Active admin 1.x.x for Ruby on Rails
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.