w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » RUBY ON RAILS » Page 1
Rails 4: Error on collection through association in (TestCase) controller index action test
Ok, figured it out. As always, was not due to some esoteric bug or syntax requirement, but rather that I did not specify session[:user_id] = @current_user.id in the test setup, which is referenced by my current_user helper method. Therefore, test framework was seeing current_user as nil. Cheers.

Categories : Ruby On Rails

custom error message for validates_length_of :maximum and :minimum on ruby on rails
The newer notation for this is: validates :user_name, length: { minimum: 5, maximum: 30, too_short: "The user name must have at least %{count} characters.", too_long: "The user name must have no more than %{count} characters." } More examples are listed in the documentation. The old validates_length_of type methods are left in there for legacy support but should probably b

Categories : Ruby On Rails

AngularJS and Rails application security in AWS
This seems an Authorization bug in your Rails API. Who is the controller that answer to the route /users? Let's say it is, for e.g., UsersController: in this case, you could have an action def index @users = User.all end or something similar, that returns the information you see. Is difficult to give you a solution, without knowing if you need this action (maybe is just auto-generated boile

Categories : Ruby On Rails

No Route Matches [GET] "/exchanges/3/mark_arrival
you have defined your custom route for POST. but you are using the route with GET change your route to GET resources :exchanges do patch :update_ordid, on: :member get :mark_arrival, on: :member end

Categories : Ruby On Rails

How to save associations with ActiveRecord Ruby On Rails
Calling tasks.create(task_params) you're actually creating a new task for both the type and the user. Instead, you just want to set the associations like this: def create @task = Task.new(task_params) @user = User.find(5) @type = Type.find(params[:type_id]) @task.user = @user # Just set the reference! @task.type = @type # Just set the reference! if @task.save redirect_to @task

Categories : Ruby On Rails

Syntax for rspec expect for find_by with an sort_by clause
The easiest way to do this is to write two expectations: Client.should_receive(:find_all_by_status).with('active').and_return([@client]) Client.should_receive(:sort_by) Also I second the earlier comment about using order instead of sort_by for performance reasons.

Categories : Ruby On Rails

Is there anyway to create a link to two paths in 1 ahref?
Something like this, you can look up more options for the ajax in the jquery docs, and there will undoubtedly be somethings you need to change for turbolinks. <%= link_to "#{activity.trackable.user.first_name} added a comment to '#{activity.trackable.node.name}'", activity.trackable.node, data: { read_url: "#{mark_as_read_activity_path(activity)}" }, id: "unread-notification" %> Here is t

Categories : Ruby On Rails

"has_two" model relationship with polymorphic model?
Your schema doesn't make sense to me - that places belong to lodgings etc. Surely there's a fixed number of places, and then they can have a number of different things in them? In your schema the same place could be in the database lots of times which seems wrong. I don't think that polymorphic associations are the way to go here either. I would model this like so: class Place has_many :lod

Categories : Ruby On Rails

CORS issue using Grape API and Heroku
You get Access-Control-Allow-Origin error every time you made a request. This is probably because your server API does not respond to OPTIONS requests with the headers required for CORS. You can check it in the development console -> network tab if you are using Google Chrome. It's interesting that some Javascript frameworks do make an OPTIONS request before a normal request is sent to the se

Categories : Ruby On Rails

Using a single html template for Rail view and Angular Template
I'm mot sure what exactly you mean by text heavy page. But what about other solution - extract all text to JSON file with keys (some sort of translation file). For example: { "title1": "Title", "paragraph1": "lore up sum. .." } Then you can load this JSON in your rails controller and pass it to view that render text parts from it. <h1><%= @text ['title1'] %></h1> <p>&l

Categories : Ruby On Rails

Rails: How to Expire Fragments with stale assets
According to the Rails Cache Guide, You can expire a fragment expire_fragment(controller: 'products', action: 'recent', action_suffix: 'all_products') You can even name your cache segment, ie <% cache('some_image') do %> *Your code here* <% end %> And then expire it by that name expire_fragment('some_image')

Categories : Ruby On Rails

Rails SASS compiler doesn't know compass animation
Try using the following combination of gems in your GemFile: gem "sass", "~> 3.2.19" gem 'sass-rails', '~> 4.0.4' gem "compass", "~> 0.12.7" gem 'compass-rails', '~> 2.0.0' And then make sure you have the following lines at the top of your scss file: @import "compass"; @import "compass/css3";

Categories : Ruby On Rails

no implicit conversion of ActiveSupport::SafeBuffer into Integer
There is no FormHelper has_many. It seems, you want to create fields for a has_many association. The Helper for that is fields_for. Try: = semantic_form_for @post, as: :post, url: client_panel_discussion_posts_path(resource), html: { data: { discussion_posts_url: client_panel_active_submission_discussion_url(resource.client_application, id: resource.slug) }, multipart: true}, builder: ActiveAdmi

Categories : Ruby On Rails

Template not found with HAML on Rails 4
While Rails is generally pretty good about picking up on changes made to your application when in the development mode, any modifications to files outside of app/ and config/routes.rb do require a restart. If you're using the rails server method, stop and start that. If using a system like Pow then touch tmp/restart.txt. Alterations to Gemfile require an explicit restart as this might change som

Categories : Ruby On Rails

Rails - Parameters not being saved when using nested forms in Cocoon
You use genre_attributes while genres_attributes (plural form) is defined in your controller. Change it to: def movie_params params.require(:movie).permit(:title, :release_date, :summary, genreships_attributes: [:id, :genre_id, :_destroy], genre_attributes: [:id, :_destroy, :name]) end

Categories : Ruby On Rails

why can i not create a home page in ruby on rails
Your question has very little detail, so it's not clear at all what you're using, I'm guessing you're on Windows, and I googled your error and it came up with a bunch of vagrant links so I'm guessing you're using vagrant. There's this issue and although it's closed, the author's comments suggest that he's still working on a fix. Update Sorry, I just noticed that the owner says it's fixed for th

Categories : Ruby On Rails

Rails how can I get all custom validate methods that defined in a model
I doubt this is possible. Just tried Person.validators but it does not return custom validation methods. If you really want validators_on and validators to return all validators, you can create a custom ActiveModel::Validator class and register it in your model with validates_with.

Categories : Ruby On Rails

No such file or directory, not pointing to the right file - Rails
I will answer myself: I don't know where this backup files came from, but I just removed them, and restart the server and all start working again! Thanks Max Williams for the effort!

Categories : Ruby On Rails

devise overriding sessions controller
More simple way to do what are asking about is to add before_filter :confirmation_notice in you application_controller and check whether current_user.confirmed? or not. ex :: before_filter :confirmation_notice def confirmation_notice flash[:notice] = "my message here" unless current_user.confirmed? end Do not forget to configure your views to show this flash notice. This to learn how to co

Categories : Ruby On Rails

how to force Cache-Control to no-store in rails 3.2.20
With Rails 3.2 the gem no_cache_control only works when the rails app is booted in production mode. Can test this by booting your app in production mode with: rails s -e production Note: make sure you have your database.yml pointing somewhere valid for the production environment.

Categories : Ruby On Rails

Get summart information for Sunspot search paginated collection
@search = Sunspot.search(Blogpost,Employee) do fulltext 'showcase OR dan' end ###group by class ###edited answer using results########## @search_items=@search.results.flatten.compact.group_by(&:class) ##get individual models @blogs=@search_items[Blog] ##get the count @blogs_count=@search_items[Blog].count @employees_count=@search_items[Employee].count ##

Categories : Ruby On Rails

How to add attributes that are not present in the model to the object in rails?
You can simply add an attr_accessor to your model: class Cloth < ActiveRecord::Base attr_accessor :cloth_type end c = Cloth.first c.cloth_type = "whatever" c.cloth_type # => "whatever" You can also add the attribute to all records (it will not be an attribute in the traditional sense) using the select method. clothes = Cloth.select("*, 'whatever' as cloth_type") clothes.first.cloth_

Categories : Ruby On Rails

How to test that a view helper renders a partial?
Where are you testing it in? Make sure render_views is called. In any case, do you really care it's rendering that partial? What if the file name is changed, or you decide to change the implementation using html helpers instead. None of this matters to the output. I would personally assert the output instead. Depending on how complex the output is you could do it in a view test or just simple uni

Categories : Ruby On Rails

many belongs_to and has_many in single line
Unfortunately, not. AFAIK this is not possible and even the documentation doesn't seems to allow this. What you can do, is to define a metaprogramming method that iterate over an array and create this associations. But not sure if it worth it. EDIT Just an example of what I mean by metaprogramming method Create a file app/models/concerns/associate.rb module Associate extend ActiveSupport::Con

Categories : Ruby On Rails

remove the need for main_app prefix in path helpers in main app
I found an answer to my question here: http://candland.net/2012/04/17/rails-routes-used-in-an-isolated-engine/ What I needed to do was to specify a helper like this in the engine: module MyEngine module ApplicationHelper def method_missing method, *args, &block if method.to_s.end_with?('_path') or method.to_s.end_with?('_url') if main_app.respond_to?(method) mai

Categories : Ruby On Rails

Rails Internacionalization datagrid
class PatientsInnsGrid include Datagrid scope do Patient.includes(:plan) end filter(:name, :string, :header => "Nome") {|value, scope| scope.where("name ilike '%#{value}%'")} # filter(:created_at, :date, :range => true) column(:name, :header => "Nome") do |asset| format(asset.name) do |value| content_tag(:strong, value) end end column_names_filter(:header =&

Categories : Ruby On Rails

Update the database with new values after a migration
You can do it in migration: class AddDurationToSessions < ActiveRecord::Migration def change add_column :sessions, :duration, :integer # Find and update all older session record Session.find_each do |s| # new duration calc_duration = s.end_time - s.start_time # update session with new duration s.update(duration: calc_duration.to_i) end end end

Categories : Ruby On Rails

ruby solr search within object rather than in models
I'm not aware of such syntax current_user.customers.search Guess it just works, because the search method is defined on the Customer class. You should index all user_ids within Customer Index, then pass the proper with scope. class Customer has_and_belongs_to_many :users searchable do integer :user_ids, multiple: true .... end end Customer.search do with :user_ids, curre

Categories : Ruby On Rails

Javascript isn´t precompiled
For Rails 3.2 you have to tell Sprockets explicitly which additional libraries it has to precompile. #config/application.rb config.assets.precompile += %w(js/jquery.dataTables.js js/jquery.dataTables.bootstrap.js configure_sort_datatable.js) By default it is: [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) }, /application.(css|js)$/ ] http://guides.rubyonrails.org/v3.2.13/asset_p

Categories : Ruby On Rails

Encrypted cookies in Rails 4
Why you can't simply use the session instead of custom cookies? Would be simpler in my opinion... session[:discount] = 45 User will not be able to see this information, because it is stored in the server memory. This way, you can use just the built-in, easy-to-use session cookie that rails automatically gives you.

Categories : Ruby On Rails

How to pass custom url to SOAP Action in Savon
You can add the SOAP action to your client call: response = client.call( :send_actions, message: { }, soap_action: "my_action_as_string" )

Categories : Ruby On Rails

Apache Solr - Error Creating SolrCore
I created a new core by cloning the folder collection1, then chooose the file core.properties and change name="Your folder". P/S: http://www.nopaccelerate.com/wiki/configuring-apache-solr-to-use-with-nopaccelerate/

Categories : Ruby On Rails

Ruby on rails button that will not redirect to another page but does it's action on the same view
Suppose that you want to have that button in an index page of some controller. If you add something like this (I'm using HAML here): = link_to "Something" Then clicking the link will refresh the page but calling the index method of your controller again before rendering. Now the only problem is to figure out if the index method has been called by clicking on the Something link or just by callin

Categories : Ruby On Rails

Mailer not sending emails rails 4
I have just copied my code from previous project config.action_mailer.default_url_options = { host: 'localhost:3000' } config.action_mailer.delivery_method = :smtp ActionMailer::Base.smtp_settings = { address: 'smtp.gmail.com', port: 587, domain: 'gmail.com', user_name: 'mailme@gmail.com', password: 'pwd'

Categories : Ruby On Rails

No route matches [PATCH] "/"
You should simply have: <%= form_for @post do |f| %> Rails will create proper action path and use proper HTTP method automatically. Your example doesn't work directly because you used wrong URL helper. You don't want to route to root path, but to posts#update action, so it should be: url: post_path(@post). You should also set @post variable to hold actual instance of Post that you wan

Categories : Ruby On Rails

Sending basic email notifications to self
Cancel the render using: def send_mail ActionMailer::Base.mail(:from => "me@example.com", :to => "myemail@gmail.com", :subject => "Contact request", :body => "test").deliver render nothing: true end

Categories : Ruby On Rails

Custom Method Route in Rails
Your routes mean that this random action will be accessible via /answers/random path. Plus your resources :answers line (the one without block) should be removed. You may find more info in Rails Guides.

Categories : Ruby On Rails

Ruby URI.enocde with Google Maps encoded polylines
Try this : require 'cgi' unescaped_url = "http://maps.googleapis.com/maps/api/staticmap?size=400x400&path=weight:3%7Ccolor:orange%7Cenc:`qdlEa`zh[?@?????@???????????@????A??@???????????????A?AAA?A@CBCBC@EDE@C@C?E@C?A??AA?AAA?A@@??@A???AA????@?@@@@BBB@BDD@BBBDD??@??@B@@@BBD@B@B?D?B?DADCFCDEBGDIBIBG@EBG@E@G?EAEAECEEIGAG?GBKHEFEJEJELEJCJCJEJEJCH?@?@???@??A?C@EBG@G@E@C?GBIDKHILGR?XBLFFFBF?JCD

Categories : Ruby On Rails

Get number of assertions in rails application
Each test will stop at the first assertion that fails. So if you have more than one assertion in a test the number will grow as the earlier assertions start to pass. The number of assertions shows is the number of assertions that were executed, not the number in the test code. There is no way that I am aware of to get the number of assertions in the test code, regardless of passing or not. Why do

Categories : Ruby On Rails




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