w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » RUBY ON RAILS » Page 4
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

ActiveRecord enum returning nil, even if it has a value
It looks like your field type for the database entry of building_type is a String, instead of an Integer (which is what enum is mapping to according to the documents). Try to change the database schema and it should work.

Categories : Ruby On Rails

Is there anyway to create a centralized partial in Rails 4?
You can actually render partials from any folder. For example, in users/show.html.erb you can render a partial _info from, say, transactions. <%= render 'transactions/info' %> A common thing to do is to put such shared partials into a separate directory with a descriptive name (I use "shared"). <%= render 'shared/filter_panel' %>

Categories : Ruby On Rails

Updating rails has_many through relations
First solution: def self.update_agency_specializations(agency, params) attributes = params.require(:agency).permit( { cruise_line_ids: [] } ) agency.cruise_line_ids = attributes[:cruise_line_ids].select{ |x| x.to_i > 0 } agency.save end !agency.errors.present? end In short, don't build anything. Let Rails do the job. Second solution: def self.update_agency_specializations(ag

Categories : Ruby On Rails

error while loading route: - why am I not retrieving data form rails?
The promise returned by your model hook is rejecting. To found out why, replace the code in your model hook with this: App.PostsRoute = Ember.Route.extend({ model: function () { return this.store.find('post').catch(function (error) { debugger; }); } }); When you load the route in your browser, the debugger call will pause execution, and allow you to look at the error being rep

Categories : Ruby On Rails

Rails compare time column with now
First, you should move your logic to your model. Second, the Rails :time datatype still stores a date into the database (even though it isn't used). We'll have to manually strip the date: Class Course < ActiveRecord::Base def status t = Time.now.utc.strftime("%H%M%S%N") end_time_f = self.end_time.utc.strftime("%H%M%S%N") begin_time_f = self.begin_time.utc.strftime("%H%M%S%N")

Categories : Ruby On Rails

Automatically defining a variable in Rails console
If you're fine with instance variables, you can add those to ~/.pryrc @f = Foo.last With local variables this won't work, because they're local to their scope (hence the name). What I do myself, is have all of the "setup" commands in a separate text file. Then in the new rails console, I just paste it. I don't have to re-type the same definitions with every console restart No pollution in t

Categories : Ruby On Rails

Create action not saving data on the database
Writing here since in the comments we don't get nice formatting: Let's make it easier. I assume your controller is called CountriesController so: Remove that default route & add resources :countries in your routes. Next, in the form: <%= form_for(@country, url: countries_path) do |f| %> ... <% end %> Now you should see in the logs that you are making a POST request. You can

Categories : Ruby On Rails

Can't convert Hash to JSON before :show action
You can visit below link http://www.rexfeng.com/blog/2012/12/convert-a-ruby-hash-into-valid-json/ I think you have to write require 'json'

Categories : Ruby On Rails

Rails erb alterantive to fields_for find specific record
<%= f.fields_for group_parameters, @specific_records do | builder | %> Attribute <%= builder.text_field(:name) %> <% end %> Fetch data from DB as per your criteria and assign to @specific_records

Categories : Ruby On Rails

Rails Call Custom Controller Action from Custom Form
Yah, I got your point. So you wanted the following thing: You wrote an custom action You wanted to submit a form that action You have registered your action in the router. So let me answer the following solutions and find some mistakes you made in your code. # in route.rb resources :exchanges do patch :update_ordid, on: :member # this is the best practice I would say, #when you ar

Categories : Ruby On Rails

How to implement a HABTM in Ember?
Well, at a minimum you're going to need to add a couple of belongs-to relationships on your appointment model: App.Appointment = DS.Model.extend({ ... physician: DS.belongsTo('physician'), patient: DS.belongsTo('patient'), ... }); Thus, whenever an appointment is saved, its child relationships will be saved with it. I assume that's what you want, since that's how the db is structured in

Categories : Ruby On Rails

Active Admin - dropdown for row
I was able to get it to work, and I still have no clue as to why I needed to insert a blank string at the beginning of the collection array. Perhaps this has to do with active admin changing the formatting around. This is what I came up with for anyone who runs into this problem: panel 'Law Firm'do table_for(bc_user) do column 'Law Firm' do select :law_firm_id, collection: options_for

Categories : Ruby On Rails

How to call function in ruby
In Ruby, you must first define a method. You do that using the syntax def method_name # code goes here end To call the method, you simply type in the method name method_name In your case, you had the first step down def install_apache end You need to add another line in your code like so install_apache

Categories : Ruby On Rails

Bootstrap-saas not showing up glyphicons-halflings.png
Bootstrap 3 switched from using bitmap icons (PNG) to icon fonts, so glyphicons-halflings.png are no longer in Bootstrap (hence the error): instead a set of icons is loaded as a font, each separate icon is placed using CSS classes with certain font-family and content (in a nutshell, in fact it's a bit more complicated). Migration from 2.x will be tedious, that's for sure. In fact, there is a migr

Categories : Ruby On Rails

What's a good way to include code from a .rb file in my controller?
Normally this is handled with Concerns in Rails 4. You can achieve a similar effect in Rails 3 by declaring a module and using that: module SpreadsheetCreator def create_spreadsheet # ... end end So long as this is named spreadsheet_creator.rb and is in a path that the ActiveSupport autoloader can find it, you don't need to do anything special to include it. app/helpers or app/models sh

Categories : Ruby On Rails

Rspec 3: can't check class type
Your validator method is returning the class DefaultValidator and/or BaseValidator. In other words, those are not instances of those classes, but their class is Class. The be_a and be_a_kind_of matchers are for asserting that an object is an instance of the Class or Module argument that is passed to them. That's why your first code sample fails, but the second one passes. The second code snippet

Categories : Ruby On Rails

Rails 4 ActiveRecord has_many length condition
Not a direct answer to your actual question, rather an alternative, but you get a big performance boost on association counts using the 'counter_cache' feature in rails: class Student belongs_to :school, :counter_cache => true You also need to add a 'students_count' column to the schools table, with a default of 0. Then when an association is created/deleted this counter is automatically u

Categories : Ruby On Rails

Search statistics on Searchkick
I would try using the "conversions" feature from searchkick. You can use that to persist queries as listed in the readme. I haven't tried it myself, but I would thisnk Redis would be a good choice to persist these data.

Categories : Ruby On Rails

Call a Model that has no controller from another file
There is a nice blogpost which gives you the rundown on how to connect to ActiveRecord without rails. In a nutshell, you need to require your AR files, and then call establish_connection with the correct configuration: Active record works just fine and dandy without rails, but it needs things to be just so. To start, get the gem and add it to your gemfile. Next, make all of your classes i

Categories : Ruby On Rails

Create an array with different sales created at the same time Ruby on Rails
If you want to group all of your sales you should be able to do: Sales.all.group(:client_id, :created_at) Or if you're trying to group by :created_at and then :client_id just switch the order. Though just a note, I would not recommend grouping by :created_at since, unless your processing tons of transaction, you will rarely have the duplicate times. You don't need to write raw SQL since Active

Categories : Ruby On Rails




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