w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » RUBY ON RAILS » Page 3
How do I prevent RSpec from using "Rspec.describe... " and "type: ..." in generated specs?
If you look at the template in the rspec-rails github repo you can see there is no option to do this via config variables. But you should be able to customize it by just creating a file in your lib/generators/rspec/model/templates/ that is called model_spec.rb for creating a custom generator for your models. It's just an erb template as you can see in the link above: require 'rails_helper' <

Categories : Ruby On Rails

Any option to post-process returned value in long conditional, other than setting variables for each statement?
def some_method(x) date = if x == 1 Date.today elsif x == 5 Date.today + 2 else Date.today - 2 end date + 20 end If you have 10 if statements it is probably better to refactor code using case-when like this: def some_method(x) date = case x when 1; Date.today when 5; Date.today + 2 else; Date.today - 2 end date + 20 end

Categories : Ruby On Rails

Highmaps with US States in Rails
Finally able to make it work with the gem itself, but i have to explicitly include the //= require highcharts/modules/map with the file that is available in http://www.highcharts.com/download for highmaps plugin, available in Highmaps-1.0.4/js/modules/map.src.js Check the issue in github

Categories : Ruby On Rails

Creating a Contact Us
I'm going to expand my comment here as an answer. The error that you're getting No route matches {:action=>"send_mail", :controller=>"home"} makes it pretty clear what the underlying problem is with your contact form not working. Anytime you're going to do something on the server side (like call a controller action) you need a route that maps a request to a controller and action. If you open up y

Categories : Ruby On Rails

Generate parameters in ruby on rails
I think you want this, I am assuming that both id and description are in performance_area object <%= form_tag({:performance => :update}, :method => :put) do %> <% @performance_areas.each_with_index do |performance_area, i| %> <%= hidden_field_tag :id, performance_area.id, :name => "performance_areas[#{i}][id]" %> <%= hidden_field_tag :description, performan

Categories : Ruby On Rails

Devise: Is it possible to NOT send a confirmation email in specific cases ?
So according to devise confirmable module you can skip to send confirmation and email by following code. def confirm_your_type_user_without_confirmation_email # check your condition here and process the following self.skip_confirmation! self.confirm! # condition may end here end Now lets call it on create hook. class User < ActiveRecord::Base after_create :confirm_y

Categories : Ruby On Rails

Port-forwarded Rails app in Docker seems to cause CSRF exception
From a cursory reading of the 'protect_from_forgery method', we find the following: def protect_from_forgery(options = {}) self.forgery_protection_strategy = protection_method_class(options[:with] || :null_session) self.request_forgery_protection_token ||= :authenticity_token prepend_before_action :verify_authenticity_token, options append_after_action :verify_same_origin_reque

Categories : Ruby On Rails

Nginx not serve static assets in rails 4 assets pipeline
I use something like this to serve static assets if they exist location / { try_files $uri @app; } location @app { # rails app stuff here... } Perhaps you're just missing a try_files directive like above.

Categories : Ruby On Rails

Rails: add addtional html into content_tag
Could you not make the change in css? .active { font-weight: bold; } You can certainly nest content_tag to add strong node: def nav_link(link_text, link_path, additional_class = nil) class_name = current_page?(link_path) ? 'active' : nil content_tag(:li, :class => class_name) do content_tag(:strong) do link_to link_text, link_path end end end Update: You could ch

Categories : Ruby On Rails

Group sales by the person who made them and time they were made. Rails and Postgresql
May I suggest a little tweak on your current approach? Add an orders model that groups these sales together because it makes more sense and it's a lot more "rails way" than trying to group by created_at date which might cause some bugs down the line. Here's what I suggest: order id user_id class Order < ActiveRecord::Base has_many :products belongs_to :user end sales id order_id pro

Categories : Ruby On Rails

Rails: undefined local variable or method `signup_path' for main:Object
Are you just running this in irb? If you so this needs to be in your RSpec test not just run from the console. The "get" method here is part of RSpec: https://www.relishapp.com/rspec/rspec-rails/docs/request-specs/request-spec

Categories : Ruby On Rails

Checking for a successful charge using Stripe for rails
Yes, that's all you need to do. If the charge succeeded, Stripe will return a Charge object, and you can check its paid parameter. If the charge failed, we'd throw an exception. Cheers, Larry PS I work on Support at Stripe.

Categories : Ruby On Rails

SSH and -bash: fork: Cannot allocate memory VPS Ubuntu
Seems you have run out of memory. Many VPS servers are setup with no swap, so when you run out of memory, it will kill things off in a seemingly random manner. The easiest way to fix it is to get more memory provisioned to your VPS, likely costing more money. The next best way (other than running less stuff and memory optimizing everything running) would be to add a swap partition or swap file.

Categories : Ruby On Rails

Cant run db:migrate
What's the data store being used here out of curiosity? Is it possible to just destroy the database and start fresh by chance? If so, you can do that with: rake db:drop db:create db:migrate

Categories : Ruby On Rails

Im getting an error when trying to run a cucumber test, which manipulates a confirm dialogue using selenium-webdriver
Check the version of selenium-webdriver that you are using compared to your version of Firefox for compatibility and make the appropriate version change in your gemfile.lock file. https://selenium.googlecode.com/git/rb/CHANGES Older Firefox versions can be found here https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/

Categories : Ruby On Rails

Stripe webhook for when trial ends
When the trial period ends, there will be a customer.subscription.updated event and an invoice.created event. An hour (or so) later, you'll then either see an invoice.payment_succeeded event or an invoice.payment_failed event. From those, you'll know whether the payment went through or not. Cheers, Larry PS I work on Support at Stripe.

Categories : Ruby On Rails

Submitting form data to controller action
Check your log. In your terminal, from the window in which you started rails server, you should see a running log of the activities happening in your app. After you submit the form, you should see something like the following: Started POST "/home/send_mail: for 127.0.0.1 at xxxx-xx-xx Processing by HomeController#send_mail as xxxx Completed 200 OK in xxms This will verify a) the correct route wa

Categories : Ruby On Rails

Scope using an argument and accessing many-to-many relationship
You can't call products as a class method, because it's instance method (usage: Resource.last.products) . So that, the same applies to has_product? method: class Resource < ActiveRecord::Base has_and_belongs_to_many :products def has_product?(product) product_ids.include?(product.id) end end Usage: product = Product.first Resource.last.has_product?(product) # => true or false

Categories : Ruby On Rails

post to an update action with out an id in rails 4.1.x
You could start with something like this: # routes.rb post 'permissions_management' => 'permissions_management#update', as: 'change_permissions_management' # view form_tag(change_permissions_management_path) If it were my app, I would treat this as a singular resource, for which Rails provides out-of-the-box support. As you can see in the rake routes output, the :id param is not required fo

Categories : Ruby On Rails

Element created in helper method is displayed with html visible
Try using <%= raw helper_method %> how do display html + css tags in a rails helper method Here's api http://apidock.com/rails/ActionView/Helpers/RawOutputHelper/raw

Categories : Ruby On Rails

Rails 4 breaks Stellar.js after link
Your issue is most certainly related to Turbolinks. I have a feeling that when you call $.stellar() after a Turbolink request, the call has no effect since it's already attached to the window object and that doesn't go away during a the request. Try destroying it prior to initializing it again in the initialize function. var initialize = function() { $.stellar( 'destroy' ); $.stellar(); }

Categories : Ruby On Rails

Rails - Setting the amount of whitespace using Slim
According to the documentation You can force Slim to add a trailing whitespace after a tag by adding a >. b> Title: =@movie.title For your second (actually first) issue, after playing around with this website for a while I came up with this | #{link_to 'Edit', edit_movie_path(@movie)} | #{link_to 'Back', movies_path} the | tell slim to verbatim interpret the following line, and the

Categories : Ruby On Rails

custom routes not work when defined as "member" in rails 3.2 resources
No route matches {:action=>"new_customer_login", :controller=>"authentify/users"} This message actually indicates about insufficient arguments to build a url(id is missing). Member actions are supposed to route to a single record and collection routes to a collection of records. That's why route helpers for member actions expect to receive a model object or an id as argument. You should

Categories : Ruby On Rails

How to set up Rails dev environment on MacBook Pro running Windows 7?
I'll try to persuade you to use OS X. Windows ruby development brings a vast amount of problems with gems. Especially with native extensions. The second argument for OS X, is that it is UNIX based system, which is much closer to production environment. Nobody deploys to windows. Most of ruby tutorials and manuals require unix based system. Just give OS X a chance, and you will be much producti

Categories : Ruby On Rails

Rails 4: Slashes from to_param slug get escaped?
It is better to define custom non-restful routes for you purposes. Guides describe very well how to do it: http://guides.rubyonrails.org/routing.html#non-resourceful-routes Such approach will give you possibility to filter articles via section, date and title. On the other side your current approach looks like a hack.

Categories : Ruby On Rails

Show name of item in destroy confirmation in rails
String interpolation (#{...}) only works in double-quoted strings. Look at this example: '#{2 + 2}' => "#{2 + 2}" "#{2 + 2}" => "4" Updated line: <%= link_to item, method: :delete, data: { confirm: "Are you sure you want to delete #{item.name}? This action cannot be undone." } do %>

Categories : Ruby On Rails

ForbiddenAttributesError in Rails 4 with a has_many polymorphic accepts_nested_attributes_for form
You don't have "addresses_attributes" in your params, you simply have "address". If you want the ability to input multiple addresses (which your data model suggests) then you need to change to something like this: = simple_form_for @member do |f| = f.simple_fields_for :addresses do |address| = address.input :street1 ... As Andrey mentions in another answer you also need to add :id to you

Categories : Ruby On Rails

Ruby refactor include? that takes in multiple strings
One way to do this would be ( (@taxon.tag || []) & ["shirts", "dibs"] ).present? This might be helpful. Let me try to explain the solution: # @taxon.tag looks like an enumerable, but it could also be nil as you check it with # .present? So to be safe, we do the following (@taxon.tag || []) # will guarentee to return an enumerable # The & does an intersection of two arrays # [1,2,3]

Categories : Ruby On Rails

Agile Web Development with rails 4 - Checkout - line items invalid
You have two validations. If you really pass name, address and email, then second validation fails. validates :pay_type, inclusion: PAYMENT_TYPES What pay_type do you choose? You can get validation errors via: object.errors.messages Good luck!

Categories : Ruby On Rails

Set variable to group of field mappings in rails app with external api (salesforce)
You're not using the proper syntax for Ruby hashes. Try: def create_application constant_fields = { Name: object.name, Email: object.email } if object.type == "car" car_fields = { Wheel_Size__c: object.wheel_size, Colour__c: object.car_colour } Restforce.new.create!(constant_fields.merge(car_fields)) else plane_fields = { Wing_Span__c: object.wing_span, Tail_Number__c: object.t

Categories : Ruby On Rails

Collect Account ID'S On A Array
Use pluck @alreadyonteam = @team.accounts.pluck(:id) Recent version of Rails also introduce ids @alreadyonteam = @team.accounts.ids

Categories : Ruby On Rails

Redirection in ruby on rails
It does not work, becuase format is not defined. Either use def update # some logic... respond_to do |format| format.html { redirect_to action: "index"} end end or drop respond_to and leave just: def update # some logic... redirect_to action: "index" end respond_to is a method that lets you define how your controller action will respond to given format, e.g: def update # som

Categories : Ruby On Rails

Passing Custom Form Values to a Custom Controller Action
I'm a bit new to this myself, but I believe it's because you're calling "text_field_tag" from a form_for instead of form_tag builder object. Try just leaving off the form for object as such: <%= text_field_tag :ordid, class: "form-control" %>

Categories : Ruby On Rails

Sending complex hash/array trees to rails with jMeter
I ended up using JSON in the POST request. I got how to do that from this blog post: http://ppettitau.wordpress.com/2012/11/25/posting-a-json-request-with-jmeter/ Basically, the key thing that is easy to miss is that the headers need to be configured in a separate jMeter object from the actual request.

Categories : Ruby On Rails

Devise embedded object 'Unpermitted parameter' error
The way you've provided :shipping_details means for it to expect a simple string value, you're then passing in a hash. You should do this in your permit instead: :shipping_details => { :address, :city }

Categories : Ruby On Rails

param is missing or the value is empty: user_club - rails
The parameters need to be nested under the user_club key. Try this instead: user_clubs_path(:user_club => {:user_id => current_user.id, :club_id => @club.id, :join_date => Date.current})

Categories : Ruby On Rails

Getting undefined method error "bills" nested resources
Are you defining @user somewhere (like in you application controller)? If not, BillsController#index sets @user to nil which doesn't have a method bills. TL;DR - Define @user.

Categories : Ruby On Rails

List of Classes in Ruby On Rails
There are a few angles of attack I can think of: Most ORMs have a similar pattern as ActiveRecord, which means that model classes need to inherit from (or include) some base class, which you can then introspect for decendants (for example Sequel::Model.decendants for sequel If all of your models are declared under a known Module (namespace), you can list the classes declared under a specific mod

Categories : Ruby On Rails

Sort a Rails model by its method
If you don't mind not getting back an array, then you could probably just use sort_by. So something like Question.all.sort_by { |question| question.engagement_score }

Categories : Ruby On Rails




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.