I think that the problem here is the fact that you are accessing the Trackable object directly in the form, but you have no actual path to address the Trackable without accessing the Graph first. Ie. you have a graph_trackables_path() and graph_trackable_points_path() methods, but no trackable_points_path() method. Probably you should...
ruby-on-rails,ruby,ruby-on-rails-4
You should pass actions to the included block and perform_search_on to the class_methods block. module Searchable extend ActiveSupport::Concern class_methods do def perform_search_on(klass, associations = {}) ............. end end included do def filter respond_to do |format| format.json { render 'api/search/filters.json' } end end end end When your Searchable module include a...
ajax,ruby-on-rails-4,submit,reload
Perhaps the reason in wrong html. about_me_change partial may look like this: <div id="AboutMeForm"> <div class="UserEditsJS"> <%= simple_form_for(@user, remote: true) do |f| %> <%= f.field :about, as: :text %> <%= f.button :submit %> <% end %> </div> </div> Pay your attention that simple_form_for method receives a block which will be...
ruby-on-rails,ruby-on-rails-4,rspec,controller,rspec-rails
Stubbed methods return nil by default. Use and_return to specify the value returned by the stub:: StripeService.should_receive(:new).and_return(whatever) or using the newer syntax expect(StripeService).to receive(:new).and_return(whatever) EDIT Pardon my hand-waving. Your stub must return an object that will act like an instance of StripeService to the extent required for the purposes of...
ruby-on-rails-4,heroku,devise,sendgrid
If you switch config.raise_delivery_errors to true then you'll be able to see if there's a specific problem and work backwards from there.
jquery,ruby-on-rails,ruby-on-rails-4,pickadate
Hi please try this may be this will help you out var dates = $( '.new_leave_datepicker' ).pickadate(); picker = dates.pickadate('picker'); jQuery.each(gon.holidays, function( val ){ var newDate = new Date(val); disableDate = picker.get("disable", [newDate]); }); ...
ruby-on-rails-3,ruby-on-rails-4,sprockets,tilt
Use bundle show to get the versions of your installed gems. For a particular gem, like tilt, you can use bundle show tilt.
ruby-on-rails,ruby,ruby-on-rails-4,twitter
If you express the relation properly, ActiveRecord will do it for you class Tweet belongs_to :original_tweet, class_name: Tweet has_many :retweets, class_name: Tweet, dependent: :destroy, inverse_of :original_tweet end Tweet.last.destroy # will now destroy dependents ...
ruby-on-rails,ruby-on-rails-4,activerecord
Change your code "%#{:search}%" to "%#{search}%" def self.search(search) if search self.where("area LIKE ?", "%#{search}%") else self.all end end Hope it helps!...
sql,ruby-on-rails,ruby,ruby-on-rails-4
Your result is anomalous. This is what I get: # migration class CreateIssues < ActiveRecord::Migration def change create_table :issues do |t| t.string :path, null: false t.timestamps null: false end end end Then in the console: Issue.create path: "path" # (0.1ms) begin transaction # SQL (0.3ms) INSERT INTO "issues" ("path", "created_at",...
ruby-on-rails,ruby,ruby-on-rails-4,controller
Check Fields of the Order Model. Do you have listing_id as a column on the orders table ? Check the migration files to make sure that somewhere along the way you have added a "listing_id" field to the "orders" table.
ruby-on-rails,ruby,ruby-on-rails-4,ruby-on-rails-3.2
So, the complex part of your situation is that you have one thing (Surgery) that can be of many different types, and the different types have different fields. There are a number of different approaches to this problem, and I don't believe there's wide consensus on the 'best way'. The...
ruby-on-rails,ruby-on-rails-4,internationalization,rails-i18n
controller: @previous_month = Date.today - (1%12).months view: I18n.l @previous_month, :format => "%B" ...
ruby-on-rails,ruby-on-rails-4,associations,activemodel
As you will be able to notice, when you are using 'new', the id for the new event is not generated. The id for a record is generated only at the time it is saved to the database and two records are linked through their ids only if you haven't...
ruby-on-rails,ruby,ruby-on-rails-4,delayed-job,rails-activejob
ActiveJob is merely an abstraction on top of various background job processors, so many capabilities depend on which provider you're actually using. But I'll try to not depend on any backend. Typically, a job provider consists of persistence mechanism and runners. When offloading a job, you write it into persistence...
ruby-on-rails,twitter-bootstrap,ruby-on-rails-4,asset-pipeline
You should change "background-image:"url(image-url('lines3.png')"; into "background-image:"image-url(image-url('lines3.png')"; http://guides.rubyonrails.org/asset_pipeline.html#css-and-sass Or you can try with: background-image: url(<%= asset_path 'lines3.png' %>)...
ruby-on-rails,ruby,ruby-on-rails-4,devise
It should look like following: class ViewedLessonsController < ApplicationController before_filter :set_user_and_lesson def create @viewed_lesson = ViewLession.new(user_id: @user.id, lession_id: @lesson.id, completed: true) if @viewed_lesson.save # redirect_to appropriate location else # take the appropriate action end end end In your ApplicationController class, you can do: def set_user_and_lesson @user = User.find_by_id(params[:user_id]) @lesson =...
ruby-on-rails,ruby,ruby-on-rails-4,virtual-attribute
Instead of using attr_accessor you could create custom getter/setters on your product model. Note that these are not backed by an regular instance attribute. Also you can add a validation on the supply association instead of your virtual attribute. class Product < ActiveRecord::Base belongs_to :supply ,dependent: :destroy validates_associated :supply, presence:true...
ruby-on-rails,ruby,ruby-on-rails-4,models
So, I went and looked at code of mine that does a similar function. Here's what my create method looks like. This is creating a Student with assignment to Student Groups in a school setting (I didn't use "class" since Ruby wouldn't like that). def create @student = Student.new(student_params) if...
ruby-on-rails,ruby,validation,ruby-on-rails-4,associations
Found this : Validating nested association in Rails (last chapter) class User belongs_to :organization, inverse_of: :users validates_presence_of :organization_id, :unless => 'usertype==1' end class Organization has_many :users accepts_nested_attributes_for :users, :reject_if => :all_blank, :allow_destroy => true end The documentation is not quite clear about it but I think it's worth a try....
ruby-on-rails,postgresql,ruby-on-rails-4,amazon-web-services,heroku
To download backup b004 use the following syntax: curl -o b004.dump `heroku pg:backups public-url b004` That will download the backup as b004.dump in the current directory....
ruby,ruby-on-rails-4,elasticsearch
UPDATE (previous answer removed because it was wrong) After reading a bit about elastic search I think this will work for you def to_es_query { query: { bool: { must: musts } } } end def musts @musts ||= [{ match:{ title_en: @title } }] #possibly { term: {type: @type...
ruby-on-rails,ruby-on-rails-4,devise,bcrypt
Simply write a migration to rename the column name, it will not loose your data. rails g migration ChangeColumnName this will generate a migration file class ChangeColumnName < ActiveRecord::Migration def change rename_column :users, :password_digest, :encrypted_password end end ...
These are Rails methods: You can find valid? here and its code on Github. Likewise with new_record?, you can find a description and its source code here. Also, here is a link to the Rails repository on Github. These methods are not defined in the project, they are defined in...
ruby,ajax,ruby-on-rails-4,devise,warden
I was finding for any answer but I haven't found anything working or actual so I spend some time and solved it at my own. Here's my answer. 1. Generate Devise controllers so we can modify it rails g devise:controller Now we've got all controllers in our app/controllers/[model] folder 2....
ruby-on-rails,ruby-on-rails-4,mongoid,embedded-documents
The reason you are getting the error is because of the logic below. If you are going to need to represent many-to-many relations, do not use a document model to store your state. Use a relational one === You can't represent a many to many relation without an association/reference table/object....
sql,ruby-on-rails-4,subquery,select-n-plus-1
Here are two ways of doing it: parent.rb class Parent < ActiveRecord::Base has_many :children # Leaves choice of hitting DB up to Rails def age_of_oldest_child_1 children.max_by(&:age) end # Always hits DB, but avoids instantiating Child objects def age_of_oldest_child_2 Child.where(parent: self).maximum(:age) end end The first method uses the enumerable module's max_by...
ruby,ruby-on-rails-4,method-overriding
Any controller can have a corresponding helper. For example if you have a controller named Question (questions_controller.rb), it can have a helper named questions_helper.rb. The question helper is accesible only to the views corresponding to the question controller. Besides you will have an Application helper (application_helper.rb) which is accessible to...
ruby-on-rails,ruby,ruby-on-rails-4
So what you want is to create a new review in two scopes at once: in @venue.reviews and current_user.reviews). Oh hang on, the latter is not even defined? Let's define that on User first: has_many :reviews Then instead of just @venue.reviews use a combination of two scopes: @venue.reviews.merge(current_user.reviews).create(review_params) # ^----------------this...
sql,ruby-on-rails,ruby,ruby-on-rails-4,activerecord
You can use joins method. Group.joins(:users).where("users.mood = ?", User.moods[:good]) You can add this into your migration add_index :users, :group_id ...
ruby-on-rails,ruby,ruby-on-rails-4,acts-as-taggable-on
You need to iterate each one of the posts per tag on your controller: def index @user = current_user @tags = @user.owned_tags end on your view: <div class="tag-lists"> <% @tags.each do |tag| %> <div><%= tag.name %></div> <% @user.posts.tagged_with(tag.name).each do |post| %> <div><%= post.title %></div> <% end %> <% end %>...
ruby-on-rails,arrays,ruby,loops,ruby-on-rails-4
the problem that I see if I understand what you are trying to do is the way you are dumping idea.evaluations into @idea_evaluations. @idea_evaluations is going to be an array of arrays of evaluations not an array of evaluations as you think. e.g. [[eval1,eval2],[eval3,eval4,eval5]] instead of [eval1, eval2, eval3, eval4,...
Try saving it like this @user.brithdate = Date.new(params[:user]["birthdate(1i)"].to_i,params[:user]["birthdate(2i)"].to_i,params[:user]["birthdate(3i)"].to_i) @user.save ...
I would do: def get_days(wkn, *desired_days) get_week = Model.week(2) get_days_of_week = get_week.select { |x| desired_days.include? x.strftime("%A") } end ...
ruby-on-rails,validation,ruby-on-rails-4
You need to put this validation into you Api model: validates :name, uniqueness: { scope: :status, message: 'your custom message' } http://guides.rubyonrails.org/active_record_validations.html#uniqueness...
ruby,ruby-on-rails-3,ruby-on-rails-4,nested-forms
Your meeting_params should be like this def meeting_params params.require(:meeting).permit(:meeting_name, :meeting_description, :meeting_date, :agenda_id, meeting_has_members_attributes: [:id, :member_id]) end Notice that I added :member_id in meeting_has_members_attributes and removed members_attributes as you are not saving them....
angularjs,html5,templates,ruby-on-rails-4,slim
Try using parenthesis syntax: input#title.form-control(type='text' ng-model='product.title' server-error) This should also work: input#title.form-control type='text' ng-model='product.title' server-error=''...
ruby-on-rails,ruby,ruby-on-rails-4,activerecord
You can use the hash options of the ActiveRecord::Core#new method in your controller: @user = User.new(user_params.merge(referrer_url: create_url)) Or move all that into a separate method for a clearer and more readable code: @user = User.new(user_params_with_additional_data) private def user_params_with_additional_data user_params.merge(referrer_url: create_url) end ...
mysql,ruby-on-rails,ruby,ruby-on-rails-4
The error log says: ld: library not found for -lssl So, you need to install libssl: brew install openssl Hope it helps....
ruby-on-rails,ruby,ruby-on-rails-4
In your associations instead of fac_allocs you need to use a symbol because rails is looking a variable or method named fac_allocs instead of your associated model has_many :facs, through: :fac_allocs ...
ruby-on-rails,ruby,ruby-on-rails-4
Try giving it like this <div class="alert alert-info alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> <% flash.each do |message_type, message| %> <%= content_tag(:div, message, class: "alert alert-#{message_type}") %> <% end %> </div> Update This should work <% flash.each do |message_type, message| %> <%= content_tag :div, class: "alert...
ruby-on-rails-4,imagemagick,paperclip
solved it with +repage and not in :all so essentially it looks like all: "-limit memory 64 -limit map 128", mobile_sm: lambda{ |instance| "#{!instance.chop_top.blank? ? '-chop 0x31 +repage' : '' } -resize 640 -quality 90 -strip -interlace Plane"}, mobile_lg: lambda{ |instance| "#{!instance.chop_top.blank? ? '-chop 0x31 +repage' : '' } -resize...
ruby-on-rails,postgresql,ruby-on-rails-4,search
Because you are using postgresql: def self.search(query) where("description ilike ?", "%#{query}%") end Just use ilike instead of like. like/ilike documentation If you want to use =, both sides either UPPER or LOWER...
ruby-on-rails,ruby,ruby-on-rails-4,model-view-controller
You can use content_for and yields to create a default in your layout which views can override. # layouts/application.html.erb: <% if content_for?(:banner) %> <%= yield(:banner) %> <% else %> <div id="banner"> <h1>This is the default...</h1> </div> <% end %> /users/signup.html.erb: <%- content_for :banner, flush: true do -%> <!-- move along,...
ruby-on-rails,ruby-on-rails-4,activeadmin
You might want a lambda scope block. Try this: class Lecture < ActiveRecord::Base has_many :chapters, -> { order(number: :asc) } has_many :lessons, through: :chapters end class Chapter < ActiveRecord::Base belongs_to :lecture has_many :lessons end class Lesson < ActiveRecord::Base belongs_to :chapter has_one :lecture, through: :chapter end got it from Deprecated warning...
rails generate migration AddPermalinkToPages permalink:string After you added then you need to create the permalink on the fly when you are saving the page or updating it. I usually do it in the model so I keep the controller clean. You can define it in a PagesHelper if you want...
ruby-on-rails,ruby,ruby-on-rails-4,activerecord
It's not "through Hash", it's "array access" operator. To implement it, you need to define methods: def [](*keys) # Define here end def []=(*keys, value) # Define here end Of course, if you won't be using multiple keys to access an element, you're fine with using just key instead of...
ruby-on-rails,ruby-on-rails-4,rails-routing
REST über alles: Much of the the cruft in your routes file could be cleaned up by just sticking the rails REST conventions. This should also improve the consistency of your application. I believe that in many cases your are compromising the design of your application just to get short...
ruby-on-rails,ruby-on-rails-4,redirect
A redirect is a fresh request to Rails. You need to set @sale again in the edit action as it is not persisted from update. Alternatively, you can render the edit view directly from update if the update fails. That will preserve the instance variables from update....
You are mapping a label and trying to treat it as a radio? perhaps map the input which has type=radio, most likely then you will be able to use choose method for that element: choose("i-20-1") not sure if you really need the # prior to the id for choose method......
ruby-on-rails,ruby-on-rails-4,rspec,devise
You're stubbing create_stripe_customer as a class method, but it's actually an instance method.
ruby-on-rails-4,command-line,console
You can use Hero.where('id MOD(2)!=0').destroy_all ...
ruby-on-rails-4,activerecord,model-view-controller,scope,parent-child
Not sure whether it's possible, but it will couple most of your app to the default_scope implementation, which IMHO is a very bad idea. You might end up needing to change this implementation down the line, which is going to have pretty high impact. It will also make your unit...
ruby-on-rails,ruby,forms,ruby-on-rails-4,controller
You can use something called action_name in Rails 4. action_name gives you the name of the action your view got fired from. Now you can send this property to the method create through a hidden field like following: <%= hidden_field_tag "action_name", action_name %> This line of code will send params[:action_name]...
ruby-on-rails,ruby,ruby-on-rails-4
You can iterate all the Status records (*). In your controller, you can add: @statuses = Status.all And in your view: <%= form_for @api, :url => commons_path do |f| %> <div class="form-group"> <%= f.label :status, "Status", class: "col-sm-2 control-label" %> <div class="col-sm-8"> <% @statuses.each do |status| %> <%= f.radio_button :status,...
ruby-on-rails,ruby-on-rails-3,ruby-on-rails-4
It seems that the problem is that skip_after_action does not accept a conditional argument such as if: or unless:. Even if you pass a conditional, the skip_after_action callback always executes. Unfortunately for me, this means that it is not possible to do what I wanted to do with the code....
javascript,mysql,ruby-on-rails,ruby-on-rails-4,private-pub
I would argue that your domain modeling is really off. The whole idea of a conversation is that the parties involved take turns being the the sender and recipient. What your have modeled is a monologue. A monologue is a speech delivered by one person, or a long one-sided conversation...
html,css,ruby-on-rails,ruby-on-rails-4
Add override class in the link_to: <%= link_to "Edit profile", edit_user_path(current_user), class:"my-dropdown-item" %> Add to CSS .my-dropdown-item { a { width: 100%; color: #000 !important; } } This might need some tweaking, let me know....
I found this after I posted, worded differently, but same issue, the first answer was a workaround to my problem. Excel links not loading pages, but when the link is pasted in the browser it works....
ruby-on-rails,ruby-on-rails-3,ruby-on-rails-4,twitter-bootstrap-3,rubygems
I was able to work it out by moving my project into another directory, preferably into a different folder.
ruby-on-rails,ruby,ruby-on-rails-4,erb,view-helpers
You've set the default Date format, but you said that the column is a datetime. If you want the default Date format that you specified, you'll need to convert the value to a date: <%= movie.release_at.to_date.to_s %> ...
javascript,html,ruby-on-rails,ruby-on-rails-4,background-image
I don't really want to get deep into your code, in two words: whatever is happening is happening because you have to wait for some actions to complete before they complete (such as animations) and you never want have timeouts within intervals. This has to be helpful: var images =...
The problem lies here: params.require(:result).permit(:data) From require documentation, require ensures that a parameter is present. If it's present, returns the parameter at the given key, otherwise raises an ActionController::ParameterMissing error. You are requiring result parameter but it's missing from the params. All your values are inside data param. Removing require...
You can change the model's to: class User < ActiveRecord::Base has_many :partners end class Partner < ActiveRecord::Base belongs_to :user end And Partner model should have a user_id column If you don't have a user_id column in Partner model, you can add it by: rails g migration add_user_id_to_partner user_id:integer The intermediate...
ruby-on-rails,email,ruby-on-rails-4,devise,mailer
def welcome_email(user) # The following line is unnecessary. Normally, you do # something like this when you want to make a variable # available to a view #@user = user # You can make the if more explicit by writing # if user.id == nil, but if will return false...
html,ruby-on-rails,image,ruby-on-rails-4,svg
Remove the space after image_tag. <%= link_to '#' do %> My Project <%= image_tag('logo.svg', "data-svg-fallback" => image_path('logo.svg'), :align=> "left" ,:style => "padding-right: 5px;") %> <% end %> ...
ruby-on-rails-4,activerecord,associations
I guess your association set up should be something like this #user.rb Class User has_many :company_admins has_many :companies, :through => company_admins has_many :followers has_many :followed_companies, :through => followers, :source => :company end #company.rb Class Company has_many :company_admins has_many :users, :through => company_admins has_many :followers has_many :followed_users, :through => followers, :source...
A good test is just put a simple line of text in your template and see if you get a PDF with that line. Strip everything back so you just generating a PDF with no coming locals, just that 1 string and let me know. Here is how I set...
ruby-on-rails,jquery-ui,ruby-on-rails-4
In case anyone is wondering, this is what worked for me in Rails 4: def sort params[:video].each_with_index do |id, index| Video.update(id, position: index+1) end render :queue end ...
ruby-on-rails,ruby-on-rails-4,heroku,dns
I discovered the answer. I am on Cloudflare's network. Turns out that if on their "Crypto" panel, if the SSL is set to "flexible" then you will get the redirect loop error. Had to set it to "Full".
jquery,ruby-on-rails,ruby,ruby-on-rails-4,rubygems
Everything is OK from your side. You said that you're on Windows 7, I also experienced this problem once when I needed to run rails on windows for some reason. Than I found an answer here which helped me to get out of this problem. Actually coffee-script-source, v 1.9.x gives...
ruby-on-rails,ruby-on-rails-4,nested-forms
The problem is in your question_params. You have to add :id for edit/update to work correctly else it will create new records on every successful submit. def question_params params.require(:question).permit(:id, :content, choices_attributes: [:id, :option, :is_correct, :question_id]) end ...
ruby-on-rails,ruby-on-rails-4,inflection
The problem is : when its trying to render leaves/new its searching for Leaves constant according to your new inflector. Change it to ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.irregular 'leave', 'leaves' end ...
Seem to be pretty straightforward: https://github.com/ryanto/acts_as_votable#examples-with-scopes @item.vote_by voter: @user1, vote_scope: 'blue' @item.vote_by voter: @user2, vote_scope: 'red' @item.votes_for.size # => 2 @item.find_votes_for(vote_scope: 'blue').size # => 1 @item.find_votes_for(vote_scope: 'red').size # => 1 So you'll need a set of 5 radio buttons (for 5 colors) on your page for the user to select...
ruby-on-rails,ruby,ruby-on-rails-4
method_name param, other_method other_param is not possible in Ruby, so it's not possible with route helpers either because it is ambiguous. There's even a section about this in The Ruby Programming Language by Matz. Example: irb(main):001:0> def link_to(a, b) irb(main):002:1> puts a, b irb(main):003:1> end :link_to irb(main):004:0> def foo(a) irb(main):005:1>...
ruby-on-rails,ruby,postgresql,ruby-on-rails-4,activerecord
I don't think update_attribute is going to be useful as it will replace the array with the new value rather than append to it (but see better explanation below in --Update-- section). I'm not sure what best practices are here, but this should work to just add something if it...
ruby-on-rails-4,session-cookies,form-submit,session-state
Yes it looks like you dropped the '@' in a couple of places in your Create action: if current_customer @order.customer = current_customer end Should be: if @current_customer @order.customer = @current_customer end ...
ruby-on-rails,ruby-on-rails-4,rspec,rspec-rails,stub
Ok I have a temporary solution, which is just to use select. I.e., #run code @current_plan = Plan.select { |p| p.stripe_subscription_id == event.data.object.lines.data.first.id }.first #test code @plan = Plan.new Plan.stub_chain(:select, :first).and_return(@plan) #result of @current_plan (expecting @plan) => @plan Still though... if others have thoughts please chime in... I'm now a...
ruby-on-rails,ruby,ruby-on-rails-4
I think this is what you after: group :development do gem 'web-console', '~> 2.0' end Then use this in your view: <% console %> Reference: https://github.com/rails/web-console ...
ruby-on-rails,ruby,ruby-on-rails-4
That's a really weird way to write some erb template code. As @mudasobwa says you have quotes around the image tags which is wrong, and adding lots of strings together in the erb tag is messy, fragile and unreadable. The two image tags are almost identical so could be dried...
ruby-on-rails,ruby,ruby-on-rails-4
You do not need to use "if" in the ternary. Change your statement to look like this: <%= current_page?(root_path) ? 'active' : 'inactive' %> ...
ruby-on-rails,ruby,ruby-on-rails-4
after_create is a model callback. Not a controller callback. If you want to add a callback which is run after your create method you would do: after_action :send_email_to_subscribers, only: [:create] But, this still occurs before the response is sent and will slow down your response times! You should consider using...
The solution is convert to hash result after select from db using @user.as_json a = Hash.new a[:profile] = @user.as_json a[:profile][:contacts] = @user.contacts.all ...
ruby-on-rails-4,activerecord,has-many-through
Please try this code def inventory_status @employee_inventories = EmployeeInventory.new(employee_inventories_params) if @employee_inventories.save redirect_to inventories_path else render :action => :show end end and in your view <%= link_to 'Request for inventory', inventory_status_inventory_path(@inventory, employee_inventory => {:employee_id => 1, :status => 'test'}), :class => 'btn btn-success' %> hope this will help you....
Since you need to support both (POST /milestones and POST /projects/:project_id/milestones) the project_id to the form: <%= form_for [@project,Milestone.new] do |f| %> ... <%= f.hidden_field(:project_id, value: @project_id) %> ... <%- end -%> Or if your resource is always nested than project_id available in the params in your controller so you...
css,ruby-on-rails,ruby-on-rails-4,haml
The problem you're having is with CSS specificity. You have declared the css files in the right order. However, the rule within tour.css.scss has a lower level of css specificity and therefore cannot override the declaration in application.css.scss. To solve you can do one of three things: Rewrite the rule...
It is not recommended to use AWS Identity and Access Management (IAM) for storing application users. Application users should be maintained in a separate database (or LDAP, Active directory, etc). Therefore, creating "one bucket per group" is not feasible, since it is not possible to assign your applications users to...
ruby,ruby-on-rails-4,simple-form
This is what I ended up doing, based off this (replacing the word user with event): https://www.railstutorial.org/book/updating_and_deleting_users#sec-unsuccessful_edits events_controller.rb: def update @event = Event.find(params[:id]) if @event.update_attributes(event_params) # Handle a successful update. else render 'update' end end Maybe deleting the else render 'update' might avoid the blank "update an event" page that...
ruby-on-rails,json,ruby-on-rails-4,sidekiq
This is a terrible solution btw, you have a huge race condition in your read/store code, and you're not going to be able to use a large part of what Rails is good at. If you want a simple DB why not just use sqlite? That being said, you need...
ruby-on-rails,ruby,ruby-on-rails-4,mongoid,paperclip
Rails has the validates_associated helper (also available in Mongoid) which will call valid? upon each one of the associated objects. The default error message for validates_associated is "is invalid". Note that each associated object will contain its own errors collection; errors do not bubble up to the calling model. Rails...
ruby-on-rails,ruby-on-rails-4,rspec,rspec-rails,stub
RSpec provides no special mechanisms to access elements under test, so yes, you would need to somehow stub the id method and have it return whatever you wish (e.g. 1). To do that, you must have a way to access the event object in your test so that you can...
ruby-on-rails-4,devise,devise-invitable
Yes you should take a is_registered:boolean column in user table which contains default value "false". Now you just have to do is when user get registered that time you just change value to "true". when ever you want to check is user registered? just do @user.is_registered? or current_user.is_registered? this returns...
ruby-on-rails,ruby-on-rails-4,activerecord,rspec,nested-attributes
The issue is in sign_up_spec.rb. Your test has a let for user, which means the first time you mention user in your tests it will create a user. However, your application code is supposed to create the user itself. As I said in the comment, this is why in your...
This is something that you need to handle in the views with a proper response builder. While acts_as_api suggested by @rob works, Rails starting from v4.0 has built in support for building and sending rich JSON responses using a typical builder style DSL. It is called jbuilder - https://github.com/rails/jbuilder Just...
ruby-on-rails,ruby-on-rails-4,model-view-controller
Why this is not working? if params[:user][:user_role] render :partial => 'users/mentor' else render :partial => 'users/mentee' end params[:user][:user_role] is nil. You can check it using lots of way: Above your if condition raise params[:user].inspect Why its nil? Reason of this is You are passing new_user_path(user_role: true) user_role true, but user_role...
Comment these lines from CvattachmentUploader def extension_white_list %w(jpg jpeg gif png) end Restart server and try again. ...
javascript,jquery,html,ruby-on-rails,ruby-on-rails-4
jquery's not function will return a jquery object, not an integer. I can't validate if the rest of your logic is working but if you want to get the number of DOM elements that matches your jquery element, you should do it using the length value: if ($('PP').not('.closed').length>=2) { window.alert('already...