Monday, April 18, 2016

RoR - dynamic dropdown with checkboxes | Fixed issues

RoR - dynamic dropdown with checkboxes | Fixed issues


RoR - dynamic dropdown with checkboxes

Posted: 18 Apr 2016 06:50 AM PDT

I am looking to implement a dynamic dropdown with checkboxes in it so the sender of a message can choose multiple receivers.

Currently I just have a list of recipients under the message textarea.

_recipients.html.erb:

<% @recipients.each do |user| %>    <label for="user<%= user.id %>" >      <span class="list-group-item"><%= user.full_name %></span>      <%= check_box_tag "message[user_tokens][]", user.id, @message.users.include?(user), id: "user#(user.id)", class: "form-control" %>    </label>  

User.rb:

class User < ActiveRecord::Base      rolify    # Include default devise modules. Others available are:    # :confirmable, :lockable, :timeoutable and :omniauthable    devise :database_authenticatable, :registerable,           :recoverable, :rememberable, :trackable, :validatable      validates :full_name, presence:true,              length: {minimum: 4 }      has_many :messages, foreign_key: :sender_id    has_many :notes    has_many :homeworks    has_many :hw_comments    belongs_to :classmodule    belongs_to :student  

recipient.rb:

class Recipient < ActiveRecord::Base      belongs_to :message      belongs_to :user        validates :user_id, presence: true  end  

messages_controller.rb:

class MessagesController < ApplicationController      before_action :authenticate_user!        def new          @message = Message.new          @recipients = User.all           @recipients = @recipients.page(params[:page]).per(8)      end        def create          @message = current_user.messages.build(message_params)            if @message.save              flash[:success] = "Message sent"              redirect_to messages_path          else              flash[:alert] = "Something went wrong"              render :new          end      end        def index          @messages = Recipient.where(:user_id => current_user.id).order('created_at DESC')      end        private      def message_params          params.require(:message).permit(:title, :body, :sender_id, user_tokens: [])      end   end  

Is it possible to get the checkboxs and names in to a dropdown with collection_select for example? Happy to provide more code if required. Thanks.

Testing HTTP and HTTPS on Cucumber Ruby

Posted: 18 Apr 2016 06:50 AM PDT

I am trying to fix a bug and the impossibility to reproduce it on my local environment is becoming a problem.

Cucumber might be able to help, but I couldn't find a way to make cucumber work for me. It is specifically about HTTP and HTTPS.

I use 4 different environments. Only production and the one below are HTTPS ones and my bug only happens there exactly because of the protocol/URL generation.

Is there a way to make cucumber work under HTTPS for a specific feature?

I hope it was clear enough, although I think it is still a bit vague.

Creating many albums using ActiveRecord

Posted: 18 Apr 2016 06:58 AM PDT

It's a rake task which searches for an artists and if it exists it will store it with artists albums. I've tried to use a gem but for some reason the gem returns something I don't really need. If I search an artist it works fine though.

result = ITunesSearchAPI.lookup(:id => 372976 , :entity => 'album')  

will return this:

{"wrapperType"=>"artist", "artistType"=>"Artist", "artistName"=>"ABBA", "artistLinkUrl"=>"https://itunes.apple.com/us/artist/abba/id372976?uo=4", "artistId"=>372976, "amgArtistId"=>3492, "primaryGenreName"=>"Pop", "primaryGenreId"=>14}   

which is not what I need at all. Here's what I should get.

So I decided to code it myself and then I realized that it saves an empty model, everything in my Album is nil. 2 questions:

1) How can I fix it?

2) How can I save ALL albums, not just one?

require 'net/http'      task :artist,[""] => :environment do |t, args|      result = ITunesSearchAPI.search(:term => args.to_s, :entity => 'musicArtist')      if result.empty? then puts "Nothing was found. Try another artist."        puts result      elsif result        uniqueness = Artist.find_by(itunes_id: result[0]["artistId"])        if uniqueness.nil?          Artist.create(name: result[0]["artistName"], itunes_id: result[0]["artistId"])          puts result        else          puts "The artist already exists in database"        end      end      if uniqueness.nil?      album = URI('https://itunes.apple.com/lookup')      album_params = { :id => result[0]['artistId'], :entity => 'album'}      album.query = URI.encode_www_form(album_params)      album_response = Net::HTTP.get_response(album)      puts album_response.body      Album.create!(name: album_response.body[0]["collectionName"], artwork_url_100: album_response.body[0]["artworkUrl100"])    end  end  

NameError in PostsController#create undefined local variable or method `post_params' for #<PostsController:0x007fd289176ae8>

Posted: 18 Apr 2016 06:53 AM PDT

Posts Controller

class PostsController < ApplicationController    def index    end      def new       @post = Post.new    end      def create      @post = Post.new(post_params)        if @post.save       redirect_to @post      else       render `new`     end   end      def show     @post = Post.find(params[:id])    end      private      def post post_params      params.require(:post).permit(:title, :body)    end     end  

Can I use Whenever Gem with a Module Method in Rails

Posted: 18 Apr 2016 07:00 AM PDT

I've created a very small application in rails where I've created a module method in /lib to handle the logic.

I've also set up Whenever to run that Module Method at set times. I've followed both the readme from Whenever and these previous posts to hopefully set things up correctly.

When looking at the readme though the examples are quoted like this:

every 3.hours do    runner "MyModel.some_process"    rake "my:rake:task"    command "/usr/bin/my_great_command"  end    every 1.day, :at => '4:30 am' do    runner "MyModel.task_to_run_at_four_thirty_in_the_morning"  end    every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot    runner "SomeModel.ladeeda"  end  

My question therefore is does whenever have to reference a method in the model? or can it reference a module method in /lib? Looking at this post it seems to allude to having to have the method in the model.

My problem is that I don't have a database and so no models.

Any help would be appreciated.

Deploy Error - psych.rb:205:in `parse': (<unknown>): mapping values are not allowed in this context at line 1 column 6 (Psych::SyntaxError)

Posted: 18 Apr 2016 06:37 AM PDT

Due to network timeout, it seems the deployment couldn't complete and I had to CTRL + C to rollback. Now when I am trying to deploy again, it is giving below error.

I am unsure why this is happening since nothing has been changed/edited either locally or on server. It looks like some setting of Capistrano got corrupted/ Can you suggest what options I have to fix this ?

The deploy.rb file looks fine since I have used it till now for all the deployment. There is no problem with whenever too.

*** [whenever:update_crontab] rolling back    * executing "ls -x /home/jason/apps/leads/releases"      servers: ["64.103.76.29"]      [64.103.76.29] executing command      command finished in 669ms    * executing "cd /home/jason/app/releases/20160418060908 && bundle exec whenever --update-crontab leads --set environment=production --roles db"      servers: ["64.103.76.29"]      [64.103.76.29] executing command   ** [out :: 64.103.76.29] [write] crontab file updated      command finished in 1135ms  *** [deploy:update_code] rolling back    * executing "rm -rf /home/jason/app/releases/20160418120015; true"      servers: ["64.103.76.29"]      [64.103.76.29] executing command      command finished in 712ms  /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:205:in `parse': (<unknown>): mapping values are not allowed in this context at line 1 column 6 (Psych::SyntaxError)      from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'      from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:153:in `parse'      from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:129:in `load'      from /Library/Ruby/Gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/recipes/deploy/assets.rb:26:in `parse_manifest'      from /Library/Ruby/Gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/namespaces.rb:191:in `method_missing'      from /Library/Ruby/Gems/2.0.0/gems/capistrano-2.15.5/lib/capistrano/configuration/namespaces.rb:191:in `method_missing'  

Access first X elements in a Class (Ruby / Rails)

Posted: 18 Apr 2016 06:51 AM PDT

I've tested a couple of methods for printing the first 3 instances of my class for a Ruby on Rails application. I've already got the following working :

    <%@posts.each do |post| %>              <div class ="post content" >                <h2 class="title"><%=post.title%></h2>                  <p class="date"><%= post.created_at.strftime("%B, %d, %Y")%></p>                  <p class="body"><%=post.body%></p>              </div>      <% end %>  

But I'm trying to do the same thing but only printing the first 3 elements of the @posts variable.

.first(3) and .find(:id) haven't worked and I'm at a loss on how to iterate through the class variables.

Thanks.

Partial date in Rails

Posted: 18 Apr 2016 06:35 AM PDT

I have a date type column in my table which is taken input from a form using f.input. But, I want only the month and year to be taken from the form. Is there any way that I can hide the day dropdown or is there any other data type which can take care of this?

I18n how to get translated model name in views

Posted: 18 Apr 2016 06:26 AM PDT

I have a header in a page where I would like to appear something like this:

'Aanpassen bewoner' 'Aanpassen gebruiker'

'Aanpassen' is dutch for Edit. 'bewoner', 'gebruiker' are translated class names of Senior, User.

I have translated the active record classes in the file like this:

nl:    activerecord:      models:        user:          one: 'Gebruiker'  

Is there a way to write the header once in the views (or in helper class) so it takes the model it currently is showing and shows the translation? Ideally I would only have one line of code which I could use in all edit views of all classes (as long as they are translated of course).

Should I make most of my rails/react app in react components?

Posted: 18 Apr 2016 05:52 AM PDT

I'm building a rails app using the react-rails gem. So far I basically made everything in react components, and rendered them using the react_component helper provided by the react-rails gem. In other words, the only things I wrote in my html.erb files were the react_component renderings. On my home.html.erb, I have

<%= react_component('Home') %>  

Is this bad practice? Does it make my website slower because I'm making extra javascript files? Or does it make my website less visible through search engines?

I will eventually move onto make this a single page application (using react-router I believe? please let me know otherwise). Should I move more of my components' html into html.erb files or just leave them in react components?

No implicit conversion of Symbol into Integer. A error still no solution for me

Posted: 18 Apr 2016 06:58 AM PDT

I have a view with checkboxes and input text. I checked one checkbox and digit value on input, after submit. But have two problem... A error on params and don't save the values on my table, this is my code:

refinancings_controller.rb

 def new      if params[:authorization]        @selected_ids = params[:authorization][:contract_ids]        @authorizations = Authorization.where("contract_number in (?)", @selected_ids)      end      @employee = Employee.search_cpf(params[:search_employee_by_cpf])      @refinancing = Refinancing.new      Authorization.where(id: params[:authorization][:contract_ids]).update_all(value_solve: params[:authorization][:value_solve], situation: 2)    end  

My console this is:

Processing by RefinancingsController#new as HTML    Parameters: {"utf8"=>"✓", "search_employee_by_cpf"=>"11111111111", "authorization"=>{"value_solve"=>["", "3444555", ""], "contract_ids"=>["33"]}, "commit"=>"Reserve"}  Completed 500 Internal Server Error in 11ms (ActiveRecord: 0.3ms)    TypeError (no implicit conversion of Symbol into Integer):    app/controllers/refinancings_controller.rb:37:in `[]'    app/controllers/refinancings_controller.rb:37:in `new'  

This is a first error:

no implicit conversion of Symbol into Integer  

The other error is don't show params situation...

I have a code to convert HTML to word doc using Rails. But when I download the word doc, the styles are not applying. Any suggestions please?

Posted: 18 Apr 2016 05:44 AM PDT

I have a code which converts my HTML code to word doc using Rails. But when I download the word doc, thein-line styles are not applying. Any suggestions please?

Do sass/scss files compile to render the final css file on production on each user page load?

Posted: 18 Apr 2016 06:09 AM PDT

I am creating a ruby on Rails app with the usual tools (rails pipeline and rails sass (gem 'sass-rails') and deploy to Heroku.

I am a newbie and what I fail to understand with scss/sass is:

  • when I deploy on heroku, do only .css files go the the production servers or does each time a user load the homepage, herokus servers need to convert my scss files and the $ variables to serve the "final" css file to the client ?

I can cope with the larger compile time while in dev mode not in production (I'd rather avoid it). At least I need to know if even in production, the css given as example below, will need to go and fetch the scss files

Exemple:

.brand {      @include vertical-align(absolute);      color: $brandColor;      right: 1em;  }  

Setting up Elasticsearch on Nitrous.io

Posted: 18 Apr 2016 05:33 AM PDT

Does anyone know how to set up elasticsearch and get it running within Nitrous.io - they've removed their autoparts function which installed it very nicely & neatly for you.

Right now it's not present on my IDE when I try and query it so I'm guessing it's not even installed?

Thanks

Setting up Ruby along with android in docker

Posted: 18 Apr 2016 05:29 AM PDT

I have an issue while setting up docker container with android and ruby environment to run calabash test. I have this docker file for the android part. Whenever I am editing the docker file to install the latest version of ruby and for calabash just like below code

RUN gem install calabash-android  

I am getting error just like

/bin/sh: 1: gem: not found The command '/bin/sh -c gem install calabash-android' returned a non-zero code: 127

And after that I have tried

FROM tracer0tong/android-emulator    FROM ruby:2.3.0    RUN gem install calabash-android  

like syntax to check whether it is gonna work and seems like not. Is there any way to install both?

Cannot push to Heroku: "Could not find rake-11.1.2 in any of the sources"

Posted: 18 Apr 2016 05:22 AM PDT

I'm having trouble pushing my project to Heroku it's telling me I'm missing a gem rake 11.1.2 yet running gem list rake tells me I do have rake 11.1.2 installed. enter image description here

ID not being found in DOM when both create and destroy are AJAX

Posted: 18 Apr 2016 05:26 AM PDT

I'm running into an issue where I allow my user to create an item, but they can also delete the item from the same page.

Currently when a user adds an item, it's added to the site through create.js.erb now I also add the ability to destroy the item. If they click on delete the method is deleted, however I'm not able to remove it from the site.

The reason is that if I run $('item-13') f.ex in my console, it's not found in the DOM because it was added through AJAX. So the issue I'm having is that in my destroy.js.erb I have:

$("#item-<%= @current_item %>").remove();  

with my destroy action:

  def destroy     @line_item = @cart.line_items.find(params[:id])      respond_to do |format|       format.js { @current_item = @line_item.id }      end    end  

how can I make it so that I'm able to find the id I've attached to the div that displays the item when it's created?

After I reload the page I'm able to delete the div based on AJAX.

Why does this RSpec example require "let!" instead of "let"?

Posted: 18 Apr 2016 05:39 AM PDT

I was able to make the test work with the following code, but it seems to be weird and I don't totally understand it.

Can somebody tell me if creating the objects this way is the optimal one?

Why do I have to only use let! for the 2nd post_comment_reply creation and why don't I for the rest of the objects?

post_comment.rb

belongs_to :post, touch: true  belongs_to :user  has_many :post_comment_replies, dependent: :destroy  has_many :users, through: :post_comment_replies    def send_post_comment_reply_creation_notification(reply)    post_repliers = ([user] + [post.user] + users).uniq - [ reply.user ]    post_repliers.each do |replier|      Notification.create(recipient_id: replier.id, sender_id: reply.user_id, notifiable: self.post, action: "commented")    end  end  

post_comment_spec.rb

describe "instance methods" do    let(:post_user) { create(:user) }    let(:comment_user) { create(:user) }    let(:reply_user) { create(:user) }    let(:reply_user_2) { create(:user) }    let(:post_reader) { create(:user) }    let(:post) { create(:post, user: post_user) }    let(:post_comment) { create(:post_comment, user: comment_user) }    let(:post_comment_reply) { create(:post_comment_reply, post_comment: post_comment, user: reply_user) }    let!(:post_comment_reply_2) { create(:post_comment_reply, post_comment: post_comment, user: reply_user_2) }        it "send_post_comment_reply_creation_notification" do      expect{        post_comment.send_post_comment_reply_creation_notification(post_comment_reply)      }.to change{Notification.count}.by(3)    end    end  

Using Ransack in Rails, how can I prevent extensive processing from a user defined search query?

Posted: 18 Apr 2016 04:54 AM PDT

I've set up a page in my rails application for a user to define criteria to perform a search using Ransack. However, I've noticed that if I build a short criteria list such as, first_name = 'John', that the entire server's processing will get close to 100% and it will slow the server down dramatically. What's the best way to resolve this? Do I need to configure my SQL Server to prevent using that much processing power? Or is there something I can do in the Ransack configuration? If I need to provide some code from a certain area of the app please let me know and I can add it.

Rails Tutorial (M. Hartl) Chapter 9 (9.2.1 : Requiring logged user) Error: undefined method `user_id'

Posted: 18 Apr 2016 04:48 AM PDT

On chapter 9.2 of Hartl's Ruby on Rails Tutorial, I'm getting this 2 errors on the rake test after i made the test for redirecting user when they try to edit or update a profile that isn't theirs :

ERROR["test_should_redirect_edit_when_logged_in_as_wrong_user", UsersControllerTest, 2016-04-18 06:27:31 +0100]   test_should_redirect_edit_when_logged_in_as_wrong_user#UsersControllerTest (1460957251.39s)  NoMethodError:         NoMethodError: undefined method `user_id' for #<User:0x00564114110958>              test/test_helper.rb:24:in `log_in_as'              test/controllers/users_controller_test.rb:28:in `block in <class:UsersControllerTest>'          test/test_helper.rb:24:in `log_in_as'          test/controllers/users_controller_test.rb:28:in `block in <class:UsersControllerTest>'    ERROR["test_should_redirect_update_when_logged_in_as_wrong_user", UsersControllerTest, 2016-04-18 06:27:31 +0100]   test_should_redirect_update_when_logged_in_as_wrong_user#UsersControllerTest (1460957251.40s)  NoMethodError:         NoMethodError: undefined method `user_id' for #<User:0x00564114035628>              test/test_helper.rb:24:in `log_in_as'              test/controllers/users_controller_test.rb:36:in `block in <class:UsersControllerTest>'          test/test_helper.rb:24:in `log_in_as'          test/controllers/users_controller_test.rb:36:in `block in <class:UsersControllerTest>'  

The errors messages points to line 24 in my test_helper and line 28,36 in my users_controller_test :

test/test_helper.rb:24:in `log_in_as'              test/controllers/users_controller_test.rb:28:in `block in <class:UsersControllerTest>'          test/test_helper.rb:24:in `log_in_as'          test/controllers/users_controller_test.rb:28:in `block in <class:UsersControllerTest>'      test/test_helper.rb:24:in `log_in_as'              test/controllers/users_controller_test.rb:36:in `block in <class:UsersControllerTest>'          test/test_helper.rb:24:in `log_in_as'          test/controllers/users_controller_test.rb:36:in `block in <class:UsersControllerTest>'  

test_helper.rb :

Line 18 would be at "remember_me" in the "log_in_as" method.

ENV['RAILS_ENV'] ||= 'test'  require File.expand_path('../../config/environment', __FILE__)  require 'rails/test_help'  require "minitest/reporters"  Minitest::Reporters.use!    class ActiveSupport::TestCase    # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical    # order.    fixtures :all    # Returns true if a test user is logged in.    def is_logged_in?      !session[:user_id].nil?    end    # Log in a test user    def log_in_as(user, options = {})      password = options[:password] || 'password'      remember_me = options[:remember_me] || '1'      if integration_test?          post login_path, session: {email: user.email,                                                               password: password,                                                               remember_me: remember_me}      else          session[:user_id] = user.user_id      end    end      # Returns true inside an integration test.      def integration_test?        defined?(post_via_redirect)      end    # Add more helper methods to be used by all tests here...  end  

user_controller_test.rb :

Line 28 would be at "log_in_as(@other_user)" in test "should redirect update when not logged in" and 36 at "log_in_as(@other_user)" in test "should redirect update when logged in as wrong user".

require 'test_helper'    class UsersControllerTest < ActionController::TestCase      def setup      @user       = users(:michael)      @other_user = users(:archer)    end      test "should get new" do      get :new      assert_response :success    end      test "should redirect edit when not logged in" do      get :edit, id: @user      assert_not flash.empty?      assert_redirected_to login_url    end      test "should redirect update when not logged in" do      patch :update, id: @user, user: { name: @user.name, email: @user.email }      assert_not flash.empty?      assert_redirected_to login_url    end      test "should redirect edit when logged in as wrong user" do      log_in_as(@other_user)      get :edit, id: @user      assert flash.empty?      assert_redirected_to root_url    end        test "should redirect update when logged in as wrong user" do      log_in_as(@other_user)      patch :update, id: @user, user: { name: @user.name, email: @user.email }      assert flash.empty?      assert_redirected_to root_url    end  end  

and this is the fixture file where :archer and :michael are stored(test/fixtures/users.yml):

# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html  michael:    name: Michael Example    email: michael@example.com    password_digest: <%= User.digest('password') %>  archer:    name: Sterling Archer    email: duchess@example.gov    password_digest: <%= User.digest('password') %>  

Unix domain or TCP

Posted: 18 Apr 2016 04:38 AM PDT

I have a fairly simple Rails app that connect to Postgres server (locally).

Uptil now, I was under the impression if not specified (socket in the database.yml) the pg client connect with postgres over TCP on a loopback interface.

Fyi,this is how my configuration looks like.

{:adapter=>"postgresql", :encoding=>"unicode", :database=>"scp_development"}  

But I think I was wrong I can't sniff any packet over the loopback interface at port 5432.

sudo tcpdump -nnvvXSs 1514 -i lo0 dst port 5432

Which is letting me believe that it working over Unix domain socket.

So, is there a fairly reliable way to determine ...

Whether I'm connected to TCP socket or Unix socket?

rails device not keeping GET params

Posted: 18 Apr 2016 05:24 AM PDT

I have one running rails app with device gem. I want pass some urls with params (in url) in email. when user click on it and if user is logged in everything works (ULR is like myhost.com/myaction?my_var=xx) but if user is not logged in it redirects to sign in path. after giving credentials it lost my_var value and app breaks. (yes it goes to my action)

for now I am redirecting user to his dashboard with error msg but anyone have good solution?

How to build a dynamic model in rails?

Posted: 18 Apr 2016 04:31 AM PDT

I am building an editable user-form using Ruby on Rails. I currently have a model to store the question title and a separate model to store options for each question.

The form has a list of all the questions and for each question, the user can view the form in a drop down list.

My problem is that I want to create a model for a user that can select an option for each questions and I want to store these options for each user in the database. If the manager deletes a question from the questions table, then the user form will not have that question.

List of questions and options

And I am displaying a form to the user showing these questions by means of a form: Survey Questions

But I do not know how to create a model to store answer for all the questions for different users of the system. Can someone suggest how to create such a dynamic model?

Rails importing mixins in application scss not working [duplicate]

Posted: 18 Apr 2016 04:29 AM PDT

This question already has an answer here:

I have the following in application.scss

@import "mixins";  @import "custom";  

and then in mixins.scss

@mixin mixin1 {    some: code;  }  

and then in custom.scss

.class {    @include mixin1;  }  

Why is this saying undefined mixin mixin1??? Also all the files are placed inside stylesheets directory!

File to import not found or unreadable: fontawesome

Posted: 18 Apr 2016 04:41 AM PDT

When I worked on mac yosemite everything works fine but when I've installed el capitan something go wrong. I mean I've installed all gems in rails application, and when I run it:

Sass::SyntaxError at /  File to import not found or unreadable: fontawesome.  

Gemfile has:

source 'http://rails-assets.org' do    gem 'rails-assets-fontawesome'  end  

and at the application.sass:

@import 'fontawesome'  

what does mean's aasm column in rails

Posted: 18 Apr 2016 04:10 AM PDT

I am new in rails and I am doing one project which has this code

 aasm_column :status    aasm do      state :unregistered, initial: true      state :pending, enter: :enter_pending_state      state :activated, enter: :enter_activated_state      state :disabled        event :register do        transitions from: :unregistered, to: :pending, guard: :valid?      end        event :activate do        transitions from: [ :unregistered, :pending ], to: :activated        transitions from: :pending, to: :activated, guard: :valid?      end        event :disable do        transitions from: [ :pending, :activated ], to: :disabled, guard: :valid?      end        event :enable do        transitions from: :disabled, to: :activated, guard: Proc.new { |u| u.activation_code.blank? && u.valid? }        transitions from: :disabled, to: :pending, guard: Proc.new { |u| !u.activation_code.blank? && u.valid? }      end    end    before_create :enter_pending_state, if: Proc.new{|u|  u.pending? }  

what does aasm_column means and what is the banalities to do this

Heroku gem shows up despite having heroku toolbelt

Posted: 18 Apr 2016 04:22 AM PDT

in my project folder, when I run heroku version, I get heroku-gem/3.32.0 (x86_64-linux) ruby/2.2.0 as one of the items, however in my home folder running the same command returns heroku-toolbelt/3.42.50 (x86_64-linux) ruby/2.2.0. How can I use heroku toolbelt in my project folder?

Use instance variable in "delete_if" method in ruby on rails

Posted: 18 Apr 2016 03:57 AM PDT

I am using @registers.delete_if { |r| r.location_id != @location_id && @location_id.present?} to filter the registers so that only the ones with the chosen location_id are kept, if anything was chosen at least. The thing is that using the @location_id.present? works just fine but checking if the id's are the same doesn't. If I check hardcoded with a number like this: r.location_id != 5 it does work.

Rails how to force download on chrome ios

Posted: 18 Apr 2016 05:32 AM PDT

I have a controller action like below. The idea is to force download instead of viewing on the browser. It works pretty well on desktop both chrome, firefox and ie. However, it doesn't work on chrome mobile ios at all. By the way, the file is very small, so I did via #send_data.

def download    @attachment = current_listing.attachments.find(params[:id].to_i)      url  = URI.escape(@attachment.url)    data = open(url).read      send_data data, type: 'application/octet-stream', disposition: 'download', filename: @attachment.file_name  end  

How to integrate Paypal integration in Ruby on Rails

Posted: 18 Apr 2016 03:13 AM PDT

I am integrating payment module for the first time. I want to integrate paypal payment in my app. For this I see multiple options but I can't decide which one is better.

1) integration with Paypal (Difficult one)

2) PayPal-Ruby-SDK

3) Stripe (Looking Easy)

Which one is better? I want to use stripe but is it support paypal ? It is available in every country?

Please guide me and don't ask to search on google. NOte : Better meanz easier to implement

No comments:

Post a Comment