spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » RUBY ON RAILS » Page 2
Rails session start event handler
Sounds like your needs might best be met by setting the session variable in application_controller.rb with a before_filter: before_filter :set_session_thing def set_session_thing session[:your_variable] ||= "your_value" end That will run before every request. Is that what you're looking for? You should check out the docs here: http://guides.rubyonrails.org/action_controller_overview.html#ac

Categories : Ruby On Rails

Why ActiveModel::ForbiddenAttributesError error?
Just change the where(condition) to: where(provider: auth.provider, uid: auth.uid) The 1st approach fails because of the method #permitted? which AR calls (if defined) to sanitize the attributes. > h = auth.slice(:provider, :uid) > h.class => OmniAuth::AuthHash < Hashie::Mash > h.permmitted? > false However, a simple Hash will not have #permitted? defined, thus it will just

Categories : Ruby On Rails

How can i track the issue in production RAILS
You can track issues in production in various way. There are several answers available. But better I should share very common practice regarding a rails application. If you are using apache/nginx as your http server. You can tail there log and make the operation on browser on the same time so you can get realtime log from the http server. Next, based on your configuration (as per convention over

Categories : Ruby On Rails

Cannot install spree gem - ERROR: invalid gem: package is corrupt
Looks like you have the system Ruby installed. You need to first do: $ sudo apt-get install ruby-dev and then do: $ sudo gem install nokogiri I'd encourage you to use Ruby Version Manager like RVM or rbenv for managing Ruby environments instead of using the system Ruby on your development environment.

Categories : Ruby On Rails

Why are the nested resources for Devise authentication not working?
You have to add :operator_id to Devise's permitted parameters Take a look here Essentially, you want to go with following in application_controller.rb: before_action :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up) do |u| u.permit(:email, :password, :password_confirmation, :operat

Categories : Ruby On Rails

Rails Devise - how to open access to the site root
From Devise's how to guide which seems to describe your example. You can create two roots in your routes.rb file. One for authenticated user's and one for non-authenticated users: authenticated :user do root :to => 'visitors#some_action', :as => :authenticated_root end root :to => 'visitors#index' However, please post your ApplicationController because your example code should work,

Categories : Ruby On Rails

Rails: respond_with the same template for two methods
respond_with doesn't take template as argument. For render the same template you can use example: def create # ...... respond_with(@device, status: 200) do |format| if @device.save format.json { redirect_to @device } else format.json { render 'devices/device_response' } end end end Why works respond_with(*resources, &block): If an acceptable format is not i

Categories : Ruby On Rails

rails with postgresl database "role postgres does not exist"
Here's a list of already answered questions: psql: FATAL: role "postgres" does not exist (with -h localhost option) psql: FATAL: role "postgres" does not exist psql: FATAL: database "<user>" does not exist Depending on how you installed PostgeSQL, you may not have the role postgres. For instance, on my machine, when I install PostgreSQL via Homebrew, the ins

Categories : Ruby On Rails

Instance variable in Rails helper not set
Try using deep_merge!: def add_meta_tag_options(opt) meta_options.deep_merge!(opt) end

Categories : Ruby On Rails

Monkey patch rails 3.2 rake task
Ok, i find a way to make it work thanks to this post : How to monkey patch a rake task shipped with Rails? So my code is : Rake::TaskManager.class_eval do def replace_task(task_name, task_scope) scope_backup = @scope @scope = Rake::Scope.new(task_scope) task_name_full = @scope.path_with_task_name(task_name) @tasks[task_name_full].clear @tasks[task_name_full] = yield @sc

Categories : Ruby On Rails

Rails_admin: Should I have admin_user or user with admin role to manage users and admin panel
Good question. I use Rails Admin and Pundit in my project. I prefer having an Admin model separate from the User model. One reason is that I like to be able to "Become a user" from Rails Admin to be able to help them when they have an issue. Its easier to do when you have separate User and Admin models. The Admin model can be super simple. Generate it with rails generate devise Admin Then in y

Categories : Ruby On Rails

undefined method `attachments' for nil:NilClass
The error is quite descriptive. @gallery is nil, so you probably don't set @gallery variable in show action (code of create action is irrelevant here). So you should have something like this: def show @gallery = current_user.gallery end

Categories : Ruby On Rails

Memory usage increase with Ruby 2.1 versus Ruby 2.0 or 1.9
This is a known issue with Ruby (versions 2.1.x) and its garbage collection. After reading couple of forums/blog posts there seems to be no real solution but to do one of the following: downgrade to ruby 2.0 and wait for ruby 2.2 to be released use unicorn worker killer to restart unicorn workers once they reach certain amount of memory, preventing Heroku R14 errors some suggest tweaking your GC

Categories : Ruby On Rails

Can a Rails app be deployed without using Heroku Toolbelt? If so, how?
It's not easy (as with Heroku toolbelt), but it's possible. It involves hanging around your Heroku dashboard at least, so make sure you can access it. First off, you need a key. If you're on a Linux machine (as me), then in your home directory you should have a folder named .ssh (it may be hidden, hit Ctrl+H to reveal, again, if Linux) and a file id_rsa.pub in there. If not, you need to generate

Categories : Ruby On Rails

Enable random access to collection with MongoDB
Based on similar questions, I've come to the conclusion that having a random field is a valid solution if the collection is dynamic, meaning that documents are inserted frequently. The more dynamic the collection is, the more 'random' access you can have.

Categories : Ruby On Rails

libmysqlclient-dev installation fails
Run the following command again and hope that will install all necessary dependencies. sudo apt-get update & upgrade then try installing libmysqlclient-dev again. if you face more error, you can try the following ways. That problem is very similar to yours. http://bugs.mysql.com/bug.php?id=73522

Categories : Ruby On Rails

undefined method `name' for nil:NilClass. Can't find @followed.name but @followed is set
Change this: def showf if params[:active_relationship] @active_relationship = current_user.active_relationships.find_by(params[:active_relationship]) @followed = User.find(@active_relationship.followed_id).name @profile = Profile.find_by_user_id(@followed.id) will give u the object of profile table else "No relationship found" end end This will give you expec

Categories : Ruby On Rails

Allowing an arbitrary domain and subdomain in session_store.rb
domain: :all should do exactly what you suspect: allow sharing a cookie across subdomains. Refer to here for pitfalls regarding TLD lengths other than 1. EDIT: Here's how you do it: # config/initializers/session_store.rb DropmyemailV2::Application.config.session_store :cookie_store, key: 'key', domain: :all, tld_length: 3 # myapp.host.com is a tld of length 3

Categories : Ruby On Rails

Pushmeup Gem - Can't send push notifications in Active Admin model
I've found that the host and port are defined as follows: module APNS @host = 'gateway.sandbox.push.apple.com' @port = 2195 class << self attr_accessor :host, :pem, :port, :pass end end So you just can redefine APNS variables, as it is shown in the README: APNS.host = 'gateway.push.apple.com' APNS.port = 2195 APNS.pem = '/path/to/pem/file' APNS.pass = ''

Categories : Ruby On Rails

Rails console does not start
I found the solution of my problem here http://vvv.tobiassjosten.net/ruby/readline-in-ruby-with-rbenv/

Categories : Ruby On Rails

GitHub Import: Could not locate Gemfile
This is a very legacy codebase and bundler is not initialized. So in order to install its gem files you need to run the following command: rake gems:install checkout their environment file: config/environment.rb And they have defined some possible steps to run that project I think you should read them carefully. For your reference, I am sharing here again: rails goo cd goo script/plugin insta

Categories : Ruby On Rails

AWS::S3::PermanentRedirect in SongsController#index "The bucket you are attempting to access must be addressed using the specified endpoint"
So, you can do something like that: AWS::S3::Base.establish_connection!( :access_key_id => 'my access key', :secret_access_key => 'my secret key' ) ENV['BUCKET']='mybucket' So, now you can replace BUCKET with ENV['BUCKET'] in your controller.

Categories : Ruby On Rails

automatically create ActiveRecord parent for association
You can use first_or_create: @wallet_transaction = @user.wallet_transactions.first_or_create(attributes) UPDATE: I misunderstood the question, you should create the wallet first if none exists and then refer to the transactions through the @wallet instance. Doing so also ensures that the wallet_id of WalletTransaction is always referred to the correct wallet. @wallet = @user.wallet.first_or_c

Categories : Ruby On Rails

Generating a tree from nested set
I used this function, but on php, not on ruby: <?php //nested sets data ordered by left $data = array( array("left" => 1, "right" => 10, "name" => "P0"), array("left" => 2, "right" => 7, "name" => "P1"), array("left" => 3, "right" => 4, "name" => "P11"), array("left" => 5, "right" => 6, "name" => "P12"), array("left" => 8, "right" => 9, "name" =&g

Categories : Ruby On Rails

Radio buttons in one line with values using ruby on rails
There's definitely more setting up you will have to do, but I'll make some assumptions and show you how you can create radio buttons. <input id="critera_one" name="criteria" type="radio" value="1" /> <label for="critera_one">1</label> <input id="critera_two" name="criteria" type="radio" value="2" /> <label for="critera_two">2</label> You'll want to put someth

Categories : Ruby On Rails

Ruby on Rails: How to print contents of variable in view and make checkbox?
Solved: In the controller, need to pluck an individual field: @content = OrientationContent.where(site_id: 1).pluck(:content) In the view, structure as so: <%= form_for(:sign_ups) do |f| %> <% @content.each do |c| %> <%= f.check_box nil %> <%= c %> <br> <% end %> <% end %>

Categories : Ruby On Rails

How to add custom menu opton in Tinymce in Rails
Rather than using the default initiator from the gem you could initiate tinymce manually and create the menu item at the same time: http://www.tinymce.com/tryit/menuitem.php Something like this: <script type="text/javascript"> tinymce.init({ selector: '.my-class textarea', toolbar: "styleselect | bold italic | mybutton", setup: function(editor) { <%

Categories : Ruby On Rails

How to make if statement always returns true for Rspec?
The answer is to stub the method by using #stub or #should_receive. Can you tell me where the find_config_const method is defined? Suppose it is defined in SomeHelper. You could do: SomeHelper.any_instance.stub(:find_config_const).with('allow_sales_manage_customer_login').and_return(true)

Categories : Ruby On Rails

'x64_mingw' is not a valid platform
check your gemfile you will see there like this gem 'tzinfo-data', platforms: [:mingw, :mswin] OR gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] if you have gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] then replace this with gem 'tzinfo-data', platforms: [:mingw, :mswin] and after that save file and fire bundle update command .

Categories : Ruby On Rails

bulk email using send grid in rails
You are grabbing an array of ActiveRecord objects with @subscribers = Subscriber.where(activated: true) and passing that into the smtpapi header. You need to pull out the email addresses of those ActiveRecord objects. Depending on what you called the email field, this can be done with headers['X-SMTPAPI'] = { :to => subscribers.map(&:email) }.to_json

Categories : Ruby On Rails

How do I use || operator so destroy ccurs in either of 2 instances?
Try this way. Create a method in your app/models/user.rb(User): def find_by_passive_or_active_relatioship(id) passive_relationships.where(id: id).first || active_relationships.where(id: id).first end then in your controller: def destroy @relationship = current_user.find_by_passive_or_active_relatioship(params[:id]) if @relationship.try(:destroy) flash[:success] = "Relationship destr

Categories : Ruby On Rails

Viewing output from Ruby in terminal
After each method you could use the puts method to see the state of the techdocument variable: testdocument.gsub!(/[ ]/," ") puts testdocument testdocument.squeeze!(" ") puts testdocument

Categories : Ruby On Rails

Rails Concerns questions
@Surya, Thanks for the idea. Just to see if I got this right, you are suggesting that I should have an ApprovalStatus class with a polymorphic relation to :approvable. Something like: class ApprovalStatus < ActiveRecord::Base belongs_to :approvable, polymorphic: true end class JoinRequest < ActiveRecord::Base has_one :approval_status, as: :approvable end class PatchInstallation

Categories : Ruby On Rails

How can I convert "11/23/2014 8:35 PM" to "2014-11-16 07:45:00" in Ruby/Rails?
You can use DateTime.strptime and specify the format as the second parameter pu = DateTime.strptime("11/23/2014 8:35 PM", "%m/%d/%Y %l:%M %p") @appointment = @car.appointments.build(pickuptime: pu)

Categories : Ruby On Rails

Sending email to an admin when new ticket is submitted by a user is not sending
Well after some trial and error it turns out I had too much going on I guess. Some clarification as to why the above works for new user registration but not for my new ticket submission would be an even better answer. Below is the way I got it to work using ActionMailer. New file admin_mailer.rb and got rid of after_create and send_ticket_notifier in ticket.rb # /mailers/admin_mailer.rb #######

Categories : Ruby On Rails

Rails 3.2 Emails being delayed for 11 mins before processed by Sendgrid
I've had this also. After talking with their support, its an intentional delay, put into the system on new accounts. Their system needs to 'learn' that you are not a spammer before it will remove the delay. They said it should only be delaying for 'a short period of time', and there is no other way to remove it, other than just send legitimate emails, and wait.

Categories : Ruby On Rails

Get Rails base URL if not in controller
If you don't have a request (which you don't, in the context of a background worker), then you can't tell the URL automatically and the only way is to set it explicitly. You could set it as an environment variable, or set it as a constant in an initializer, and then get it from there.

Categories : Ruby On Rails

Form Error: First argument in form cannot contain nil or be empty
Update Users::RegistrationsController#new as follows def new if (params[:plan] == '1' || params[:plan] == '2') super else flash[:notice] = "Please select a plan to sign up." redirect_to root_url end end

Categories : Ruby On Rails

Recaptcha::RecaptchaError in RegistrationsController#create
The documentation for installation provides a default initializer like so: Recaptcha.configure do |config| config.public_key = 'XXXXXXXXXXXXXX' config.private_key = 'XXXXXXXXXXXXXX' config.proxy = 'http://myproxy.com.au:8080' end Delete the final line if you are not using a proxy: config.proxy = 'http://myproxy.com.au:8080'

Categories : Ruby On Rails


Recently Add
How do I show two different partials on every other pageview?
Ruby on Rails: Populate view based on database column values
Wrapping the bootstrap-sass gem in another gem causes asset manifests to break
.where.not with empty array
assign_attributes and save later in loop - ruby rails
File from a Delayed Job to Uploader
mongoid validate uniqueness of each member in has_many or has_and_belongs_to_many relation
Gibbon Mailchimp integration simply not working
No terminal output with caypbara / rspec / selenium-webdriver
Rack::ShowExceptions enabled in production Rails 4.0.4
Ruby on Rails access whole params hash
Can I view Rails documentation with pry?
Why isn't the confirm box working?
Polymorphic models (not associations!) in Rails
Link_to :Action won't call Controller Method -- Rails 4
Missing template when rendering a collection using local variables
rails simple_form using virtual attributes
uninitialized constant ActiveSupport::TestCase
Rails 4, Paperclip, S3 wrong url path
Neo4j gem - Updating relationship properties method
Error trying to deploy Rails app to Heroku
Modyfying before_action
CarrierWave TypeError (can't dump File) on Heroku
CanCan Ability in Rails - Giving partial manage
Uploading two images using s3 and paperclip on rails app
How to pass hash values of ActiveRecord::Base class
Ruby on rails. Heroku compile assets timeout when i add unicorn gem
Rails Template is Missing Error
Time.now.to_i different on heroku and locally
Simple rails app on Puma throws segfault, cannot handle concurrency
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.