spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » RUBY ON RAILS » Page 3
Rendering A Partial / Layout With Multiple Blocks
Take a look on rails presenters https://www.ruby-toolbox.com/categories/rails_presenters Maybe your solution is cells gem.

Categories : Ruby On Rails

String interpolation not working for Ruby heredoc constant
instead: const = <<-EOT.constantize This::Is::ThePath:: To::MyModule::#{a_variable} EOT use: const = <<-EOT.gsub(/ /, '').constantize This::Is::ThePath:: To::MyModule::#{a_variable} EOT This method that create string <<-EOF ... EOF put on the end of line, then constantize can't work properly. Removed undesired character , , s and all should work. Look my test c

Categories : Ruby On Rails

new using rails 4 - ActiveModel::ForbiddenAttributesError
In create action change params[:video] to video_params: def create if @person = Video.create(video_params) flash.now[:success] = "Thanks for suggest this video" redirect_to root_path else flash.now[:error] = "Impossible to add this suggestion" redirect_to new_frontend_video_path end end You should permit params, instead Rails raise ActiveModel::ForbiddenA

Categories : Ruby On Rails

has_many through, with conditions
You'er likely having issues with syntax. These associations: has_many :private_tags, -> { where :private_tag => true }, through: :pictures_tags has_many :user_tags, -> { where :user_tag => true }, through: :pictures_tags are fine. The problem is with: has_many :tags, -> { where :private_tag => false and :user_tag => false }, through: :pictures_tags because where clause

Categories : Ruby On Rails

What are the differences between jquery-rails and rails-assets-jquery?
The difference is, the rails-assets-WHATEVER is a package from Bower.io while the other one is from RubyGems. So, in a ideal world there's no difference between rails-assets-jquery and jquery-rails. So, you have to assume that the authors are pushing new versions at the same time to both repositories: Bower and RubyGems. However, in real world there are different maintainers of packages and the nu

Categories : Ruby On Rails

Optimising Eager Load
The best way to do this would probably be changing your data model to a polymorphic relationship and using a belongs_to association in MediaItem class MediaItem < ActiveRecord::Base belongs_to :media_content, :polymorphic => true end class Photo < ActiveRecord::Base has_many :media_items, :as => :media_content end class Video < ActiveRecord::Base has_many :media_items, :as

Categories : Ruby On Rails

Ruby on Rails - reverse add_column, add_index migration
As per my understanding you want to rollback the migration. If so then you can use the below syntax for that rake db:rollback STEP=n or rake db:migrate:down VERSION=<version_number_of_migration> which rollsback the particular migration

Categories : Ruby On Rails

Disabling/replacing paperclip in Spree Commerce
There is no simple mechanism to replace Paperclip. You should just be able to code your own solution, override any calls to paperclips methods to call your method pretty easily enough though. It just may be a bit time consuming, and possibly more time consuming than it would be for you to just deal with importing the images instead.

Categories : Ruby On Rails

rspec-mocks' doubles are designed to only last for one example
surely this is an appropriate use of a double being used in 2 examples. No, it's not. :) You're trying to use a class variable; do not do that because the variable doesn't span examples. The solution is to set the client each time i.e. in each example. Bad: @client ||= Strava::Api::V3::Client.new(access_token: 'abc123') Good: @client = Strava::Api::V3::Client.new(access_token: 'abc123')

Categories : Ruby On Rails

sprockets - precompiling a standalone asset
One way to do this is to add an initializer that generates the compiled versions directly. Add your js file to a subfolder in /app/assets/javascripts. Don't include this in application.js so it isn't added to the compiled assets. Create an initializer in /config/initializers that uses uglify directly output_file = "#{Rails.root}/public/public_script.js" input_file = "#{Rails.root}/app/assets/j

Categories : Ruby On Rails

Rails Path Helper Does Not Rewrite URL In Location Bar
This sounds like a side-effect of turbolinks. See: https://github.com/rails/turbolinks/issues/22 A little further digging reveals this issue was addressed by adding a X-XHR-Redirected-To header which turbolinks picks up on to reflect a redirect in the address bar. It works when you call redirect_to in a controller, however it does not seem to work when redirecting root in routes.rb. This smell

Categories : Ruby On Rails

Rails: What is an API's endpoint?
An endpoint, as I imagine they may be using it in this course, is simply a route defined by your rails application. In terms of an API (which can mean many things and is worth further research on your part), hitting that endpoint will serve up a resource from your application, or perform some form of action. An example may explain this better.. Say we have an application that handles users and we

Categories : Ruby On Rails

Rails/Angular: How to implement internal and external REST/JSON APIs in same app?
FWIW, I will give you my opinion. CAVEAT: I'm not a rails guy so I'm coming at this from nodejs/expressjs land. There are many ways to skin this cat, but I'll just say that you are headed in the right direction. if you want to look at a very opinionated way to do things (and one people might hate) in node, see this: https://github.com/DaftMonk/fullstack-demo/blob/master/server/api/user/index.j

Categories : Ruby On Rails

Rails 4 - Add existing association in nested resource
If you got a complicated logic like this, it's better to use something like "Form Objects" to save multiple models and relations between them. I.e. move saving logic outside of both models. access_nested_attributes_for should be used only for very very simple cases (like most of Rails's magical features)

Categories : Ruby On Rails

Capitalize lowercase letters in Ruby On Rails
1.9.3-p547 :037 > string="my house is yellow" => "my house is yellow" 1.9.3-p547 :038 > string=string.split(' ') => ["my", "house", "is", "yellow"] 1.9.3-p547 :039 > string.each do |a| 1.9.3-p547 :040 > a.capitalize! 1.9.3-p547 :041?> end => ["My", "House", "Is", "Yellow"] 1.9.3-p547 :042 > string => ["My", "House", "Is", "Yellow"] 1.9.3-p547 :044 > s

Categories : Ruby On Rails

When using Omniauth in Rails, Google_omniauth2 creates a new user if the user exists and use different auth
Found the answer! In the user.rb file, it checks whether the email is verified by Facebook or not by accessing 'auth.verified' attribute. It will only take the email and check for an existing account if it's verified. The problem is,Google does not provide that attribute. So, if someone authenticate with Google I will bypass the verification like this : if auth.provider == 'google_oauth2' e

Categories : Ruby On Rails

Rails password can't be blank error
It sounds like your parameters are not being sent to the server correctly. password should be sent as user[password] and password_confirmation should be sent as user[password_confirmation]. See documentation for hash and array parameters. Alternatively, adding wrap_parameters to the controller will wrap parameters into a nested hash. wrap_parameters :user, include: [:given_name, :family_name,

Categories : Ruby On Rails

# encoding: utf-8 don't working ruby on rails
There isn't a DOTALL modifier s in ruby. Just change s modifier to m to make it work. text.gsub(/<!--(.*?)-->/m, "") DEMO And also you don't need to capture any characters , just /<!--.*?-->/m would be fine.

Categories : Ruby On Rails

JSON not parsed in rails post
A common practice while building REST api's is to send the params as plain http attributes. For a post request they can be encoded within the message body (application/x-www-form-urlencoded). This is best explained by the following curl command: curl --data "user[last_name]=testak&user[first_name]=chuck" http://example.com/users What you've done, however is this: curl --data "user={"las

Categories : Ruby On Rails

Using a rails helper in haml, passing a hash causes syntax error
I think you just need to replace the curly brackets with the regular ones in your helper, try this: = nav_big( profile: @user, art: root_url, stories: root_url, universes: root_url, elements: root_url ) if you prefer the curly brackets then you should use this format = nav_big { :profile => @user, :art => root_url, :stories => root_url, :universes => root_url, :elements => root_url }

Categories : Ruby On Rails

Rails: Routing in rails 4
Ok i find the answer this is can be done by using member resources :companies do member do get 'jobs' end end this will give the following url /companies/company_id/jobs

Categories : Ruby On Rails

Rails4 | Paperclip: image is uploaded but it doesn't displays well (strange url is returned)
That is what Paperclip uses for cache-busting. If you want to remove it, just call @user.avatar.url(:original, timestamp: false) You can also disable this globally by putting the following in the config/initializers/paperclip.rb file. Paperclip::Attachment.default_options[:use_timestamp] = false This answer explains why you may want cache-busting in place though.

Categories : Ruby On Rails

Your Ruby version is 2.0.0, but your Gemfile specified 2.1.2 without update Gemfile
RVM and RBenv are actually similar tools. There are no practical reasons to keep them alongside each other in one session (and on one machine most of the time). They both rely on modifying PATH environment variable to get the Ruby and supplementary binaries closer for easy use. And that's what RVM complains about: PATH is not what it expects to be. That said, RBEnv apparently tampered with it. Si

Categories : Ruby On Rails

Dynamically appending .or() calls to an active record query based on array elements
You can use inject to build your query: ary[1..-1].inject(Object.where(ary[0]), :or) This form takes all the elements but the first one, and for each they append .or(ary[i]) to the result, where the initial value is Object.where(ary[0]). Another way of doing the same thing is using a block: ary[1..-1].inject(Object.where(ary[0])) { |query, cond| query.or(cond) }

Categories : Ruby On Rails

Setting up development vagrant box for Rails
you need to install the bundle gem using the rbenv gem command: rbenv global 2.1.2 # ensure all shims for current ruby version are there rbenv rehash gem install bundler # rehash again to make sure you get the `bundler` command from `rbenv` rbenv rehash bundle install Hope this helps

Categories : Ruby On Rails

Send form params to controller without a model in Rails
Use form_tag with your path. I have used /user_email/send_email. change it according to the route your have setup in routes.rb <%= form_tag('/user_email/send_email') do %> <%= text_field_tag(:subject, class: 'form-control')%> <%= submit_tag "Submit"%> <% end %>

Categories : Ruby On Rails

Strip time zone part from Time in Ruby
Are you trying to use the same literal time (ie. 10:56 ET and 10:56 PT) regardless of timezone? Or are you trying to ensure that queries are referencing the same exact time (ie. 10:56 ET and 7:56 PT)? For the former case (same literal time), just omit the %z or %Z from the strftime argument. For the latter, I would recommend using Unix timestamps with Ruby's time.to_i function and MySQL's FROM_

Categories : Ruby On Rails

Email compose view in rails
You need to create a controller which handles your view, and in that controller you need to call the mailer somewhat like this: (you'll need to change the names of your form fields to match the params in the call or vice versa) Notifier::send_email( params[:email], params[:subject], params[:body]).deliver I'd recommend to check out these RailsCasts: http://railscasts.com/episodes/61-sending

Categories : Ruby On Rails

Rails 4: f.select returns string not integer
In your create method, you should be able to quickly turn the :country param to an integer like so: @user = User.new(user_params.tap{ |u| u[:country] = u[:country].to_i })

Categories : Ruby On Rails

Rails scope with polymorphic model
Your scope is not working correctly, .last in your scope get one results instead of an ActiveRecord relation, remove .last and the scope will work fine in getting all Financials with ltm=true

Categories : Ruby On Rails

Blacklist model in Rails 4
You forgot to save the object. def downvote @advertisement.downvote_from current_user flash[:notice] = 'Downvote added.' if @advertisement.vote_registered? if @advertisement.get_dislikes.size == 30 @advertisement.in_blacklist = true @advertisement.save # there you go! flash[:notice] = "#{@advertisement.name } added to blacklist. Information sent to #{@advertisement.user.email }

Categories : Ruby On Rails

cannot update attribute within users model in custom action
Your form is not submitting the values properly may be. So inspect your params in the binery select action. record#update_attributes doesn't take a single value, it accepts hash. So the proper code should be something like: rails version < 4 if @user.update_attributes(params[:user]) in rails 4.* if @user.update_attributes(user_params) in controller make sure you have permitted the user p

Categories : Ruby On Rails

Why is my Tickets controller create action failing?
You're missing the user_id attribute when making the POST request And it's because of this line: <td><%= f.label :user_id, "User Name" %></td> you meant to write <td><%= f.hidden_field :user_id, value: current_user.id %></td>

Categories : Ruby On Rails

PayPal Adaptive Payments Rails App Configuration
Please note that our REST API doesn't have Adaptive payments functionality yet so you need to use the Adaptive Payments SDK for Ruby, which can be downloaded from here https://github.com/paypal/adaptivepayments-sdk-ruby Question 1: Do I use these credentials or do I change them to my PayPal sandbox credentials? You need to use your Sandbox account API credentials. You can view your Sandbox acco

Categories : Ruby On Rails

How to make sure that rails server is running in background on a vps
Check out this tutorial. http://gistflow.com/posts/544-runit-the-missing-how-to In a couple words - you should use supervisor, that starts your ruby server. It will restart app, when it crashed. It will start app after VPS reboot. And so on.

Categories : Ruby On Rails

Associating current_user id to imported contacts list
Okey, based on your given information you can do the following to add the current_user_id to your contact. In your ContactImportController ......... def create @contact_import = ContactImport.new(contact_params) @contact_import.user_id = current_user.id if @contact_import.save redirect_to contacts_path, notice: "Imported contacts successfully." else render :new

Categories : Ruby On Rails

no route matches post for simple search form
Just defined the form_tag in the following way. <%= form_tag url_for(:controller => 'home', :action => 'search'), :method => 'get' do %> Hope your problem will be resolved!

Categories : Ruby On Rails

Scope a model using several queries, Rails 4
Try this: scope :organizer, -> { where('cat_id = ? or cat_id = ?', 1, 8) } What wrong here: You try mix SQL operator OR and ruby method invoke. for future research test query in rails console: => User.where(first_name: 'Foo').to_sql #> "SELECT "users".* FROM "users" WHERE "users"."first_name" = 'Foo'" => User.where(first_name: 'Foo' or last_name: 'faw').to_sql SyntaxError: unexp

Categories : Ruby On Rails

Rails: 2 user ids in a single table?
In this case, each message has exactly one sender and possible many receivers. So your models could be: class Messages < ActiveRecord::Base has_and_belongs_to_many :receivers, class_name: 'User' belongs_to :sender, class_name: 'User' end and class User < ActiveRecord::Base has_many :messages, dependent: :destroy has_and_belongs_to_many :received_messages, class_name: 'Message

Categories : Ruby On Rails


Recently Add
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
Setting Up Rails to Receive HTTP POST Request
Rails: Is it safe to use params[:bar] in link_to helper?
How to add aggregated columns from SQL SELECT to AR object in Rails
Circular Dependency Error autoloading constant
Groups and Users has many oder has many through?
Rails format specifier differences
Capistrano can not create symlinks: file exist
Admin can't delete users. Ruby on Rails 3 - Michael Hartl
Don't show user name who create post
Using Wicked with Devise (2 step signup process)
RubyOnRails Rake test failures
Rails session start event handler
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.