Tuesday, June 14, 2016

Website not opening in ios facebook app | Fixed issues

Website not opening in ios facebook app | Fixed issues


Website not opening in ios facebook app

Posted: 14 Jun 2016 08:31 AM PDT

I'm currently working on a RoR application (ruby 2.3.1 and rails 4.2.3). The Facebook page from my company has a link to the application, and it's working perfectly outside of the facebook app and on the android one however it's not working on facebook ios app. As soon as the website is opened there's an error "ActionController::ParameterMissing: param is missing or the value is empty". Server side i'm validating params via Rails Strong Parameters.

The object is created in the new action:

def new    @object = Object.new  end  

And the create action persists the object:

def create    @object = Object.new(object_params)    ...    object.save  end  

The error only occurs in the ios version of Facebook app.

Create a full url link in Action Mailer without a url helper

Posted: 14 Jun 2016 08:29 AM PDT

We have an application with a javascript front-end that uses navigo library to create routes.

I would like to create a link in a email using the navigo notation. The problem is that if I create a link with link_to passing only the path to navigo, like this:

link_to 'Some link', '/#/some/custom/path'  

it will, as it should, put only the /#/some/custom/path in the link href attribute.

According to Rails Guides, if I set the config:

config.action_mailer.default_url_options = { host: 'example.com' }  

It will add the host to links created with link_to in the mailer.

Question is, since I'm not using the path or url notation with link_to, how could I create a link to the site, that uses this host property? (Because we have staging, and production servers, and the address can change)

Rails access form parameter that is an array

Posted: 14 Jun 2016 08:22 AM PDT

I have a form that allows for the entry of multiple ids like:

<input name="the_ids[]"  type="text" placeholder="Enter an ID" />  <input name="the_ids[]"  type="text" placeholder="Enter an ID" />  <input name="the_ids[]"  type="text" placeholder="Enter an ID" />  

When the form submits I get the params being passed as:

"the_ids"=>["1, 2, 3"],  

In the controller I am trying to access them as:

params[:the_ids[]].each do |id|    do_something_with(id)  end  

I keep getting the error:

wrong number of arguments (0 for 1..2)  > params[:the_ids[]].each do |id|  

The trace shows the following:

app/controllers/the_controller.rb:10:in `[]'    

I cannot figure this out. I've reviewed some other posts and tried to access in alternative syntax like:

params["the_ids[]"]  

But that produced an error stating that is was a nil class...

Please advise if more details are needed.

How to tell RSpec to restart Rails before an example is run?

Posted: 14 Jun 2016 08:08 AM PDT

Is it possible to test rspec to restart Rails before an example is run? I'm building an Engine that hooks into the Rails initialization process and the users can make some configuration changes. I want to be able to simulate those configuration changes, restart rails and test the result.

Rails Sprockets: require different JavaScript based on variable

Posted: 14 Jun 2016 08:13 AM PDT

Imagine I have a Rails application that can have multiple themes which require different JavaScript per theme + JavaScript shared between themes.

The theme is specified as an ENV variable.

How could I require a different JavaScript file based on the theme?

I would like to do something similar to this in my application.js file:

/* Theme specific */      //= require_tree "./theme/#{ENV[APP_THEME]}"    /* Shared between all themes */  (function() { ... })();  

Which obviously doesn't work. Does someone have an idea about that?

Execute PowerShell script on my rails app

Posted: 14 Jun 2016 07:56 AM PDT

I looked everywhere on how to set a script on my rails app but nothing accurate. Actually I want to create new users on Active Directory through a form which is on my app.

The idea is to let the user create his profile on the app (name,email, password), then the script will do the work to add the credentials on Active Directory.

Do you have any idea to do that?

undefined method `find_post' for #<PostsController:0x0000010b791560>

Posted: 14 Jun 2016 07:59 AM PDT

This is where i got stuck in my code:

class PostsController < ApplicationController  before_action :find_post, only: [:show, :edit, :update, :destroy]    def index  end    def show  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 edit  end    def update    if @post.update      redirect_to @post    else      render 'edit'    end  end    def destroy    @post.destroy    redirect_to root_path  end    private    def post_find    @post = Post.find(params[:id])  end    def post_params    params.require(:post).permit(:title, :content)  end  

end

I defined post_find but i am still getting error when i run code sorry for the mistakes in post i am new to rails. I want to be able to post on the forum and make edits or delete post.

filter search by location

Posted: 14 Jun 2016 07:46 AM PDT

So i have a searchkick search results page. The model looks like this

searchkick batch_size: 200, aggs: [:event_type, :gender, :brand], word_start: [:eventname], autocomplete: ['eventname']  

and the view is just a table. displaying the results.

Now i'm wanting to allow my users to search via location. so they get to the results page where the filter is. And a filter section exists.

What i want is for them to type into a searchbox a location e.g. swansea and it'd order the current events shown by distance.

Any ideas? Thanks Sam

Devise and Users Route Confilect

Posted: 14 Jun 2016 07:42 AM PDT

I get the following clicking that link

<%= link_to "(#{User.count_friend_requests(current_user)}) Friends Requests", :controller => "users", :action=>"friend_requests"%>  

i get that error

ActionController::UrlGenerationError in Devise::Registrations#edit  No route matches {:action=>"friend_requests", :controller=>"devise/users", :format=>"1"}  

routes

devise_for :users, :path_prefix => 'my'  resources :users, :only => [:friend_requests] do     get "friend_requests", :on => :collection   end  

users_controller

def friend_requests      @frnds =  User.find_friend_requests(current_user)  end  

Rails: Create a drop down list (within a form) where it's possible to select more than one value

Posted: 14 Jun 2016 08:03 AM PDT

(I've made up the example below as it's clearer than going through my specific case.)

Suppose I have a form for a User, and that the underlying User table has a personality_traits field; an array of the user's personality traits. Is there a standard way in rails to create a drop-down list so that the user can pick any number of a selection of attributes (e.g., "easy-going", "fun-loving", "quick-tempered"), and have these ultimately feed into the personality_traits field as an array? If not, does anyone know of a particularly good method?

No connection between Apache Passenger and Faye

Posted: 14 Jun 2016 07:40 AM PDT

I'm trying to deploy my Rails 4.2 app with chat to production (Ubuntu 14.04). For chatting I used gem 'private_pub', which works perfectly on my local machine. Hovewer, I have a big trouble with it on production server.

My messages are sent, but are shown only after reload. When I entered my browser console, I saw this error.

application-8275c71….js:14 GET http://localhost:9292/faye.js net::ERR_CONNECTION_REFUSED

But this file is accessible through link http://my-site.com/faye/faye.js

private_pub.yml

production:    server: "http://localhost:9292/faye/faye"    secret_token: "some numbers"    signature_expiration: 3600 # one hour  

private_pub.ru

require "bundler/setup"  require "yaml"  require "faye"  require "private_pub"    Faye::WebSocket.load_adapter('thin')  PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development")  run PrivatePub.faye_app  

I run my thin server with command

RAILS_ENV=production bundle exec rackup private_pub.ru -s thin -D -E production  

I also added this to my apache .conf:

ProxyPreserveHost On  ProxyPass /faye http://127.0.0.1:9292/  ProxyPassReverse /faye http://127.0.0.1:9292  

How can I configure my Apache or Rails app to get connected to that file properly from app?

Rspec: test number of rows in CSV output

Posted: 14 Jun 2016 07:46 AM PDT

In Rspec how do I test the number of rows that are in a CSV file?

I have created a CSV file in a mutation. I am able to test the output of the CSV by checking if certain text is included. However, I would like to be able to test the number of rows that are in the output.

Please find an example of what I have tested so far below which passes:

describe "#execute" do        it "creates a CSV for the specified content" do        outcome = mutation.run(mutation_params)          expect(outcome.result).to include("Name")      end    end  

comparing current time to UTC

Posted: 14 Jun 2016 07:35 AM PDT

I'm trying to query the DB for the opening time of a store.

The open_at when queried from the DB returns:

2000-01-01 16:18:00 +0000  

When I run Time.current it returns

Tue, 14 Jun 2016 16:32:46 CEST +02:00  

Now I'm trying to do:

store.business_hours.where('open_at <= ?', Time.current)  

it returns an empty ActiveRecord array as such:

#<ActiveRecord::AssociationRelation []>  

now what I'm trying to do is make it so that the open_at in-fact shows, and that it's able to understand the time zone difference.

SimpleCov to include engine codes at coverage report - Rails testing

Posted: 14 Jun 2016 07:20 AM PDT

I am using SimpleCov as a coverage tool in my rails app. At this app, the code is divided to engines and i am including the engines to my app according to some inputs.

The problem with simplcov it generates the coverage report for the code inside the app only and it ignores the code at the engines. So does anyone has an solution for that?

Using awesome_nested_set, how to define a has_many relation with all the descendants as well?

Posted: 14 Jun 2016 07:18 AM PDT

I have a simple product and category models along with product_category models that establishes presence in the product category tree.

Product is always placed to the deepest possible categories.

It is intended to call

root_category = Category.find(1)  root_category.products  

and basically get all products that have a category assigned.

What happens is that I can only get products from one of the descendant category if said category is selected instead of root_category using

category.self_and_descendants.includes(:products)  

How can I make it that I call category.products that does basically the above?

== app/models/product.rb ==  class Product < ActiveRecord::Base    has_many :product_categories    has_many :categories, through: :product_categories  end    == app/models/product_category.rb ==  class ProductCategory < ActiveRecord::Base    belongs_to :product    belongs_to :category  end    == app/models/category.rb ==  class Category < ActiveRecord::Base    has_many :product_categories    has_many :products, through: :product_categories  end  

How to hide redmine header and footer for a specific page?

Posted: 14 Jun 2016 07:18 AM PDT

I need to show a page without redmine header and footer inside an iframe. Please help me !

Trying to assign contents of a variable to params[:

Posted: 14 Jun 2016 07:36 AM PDT

I need to grab the contents of a form before the submit key is pressed in order to save the user input. If the form is submitted and validation fails then the user input is lost.

I have the main contents of the form working ok with session variables. However I want to take the params[:images] from paperclip and save that to a column in a table and then load it back into params[:images]

My form has

<div class="field" title="You may attach one or more documents to this observation: Pictures, word documents, spreadsheets, etc">    <%= f.label :Upload_attachments %><br>    <%= file_field_tag "images[]", type: :file,  multiple: true %>  </div>  

in the respond_to for create, I can write the contents of params[:images] to a table with

 if params[:images]        temp_data = TempDatum.create( item: '2',  data: params[:images])      end  

That works and results in something like the following in data

[#, @original_filename="2016 06 13 capture.JPG", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"images[]\"; filename=\"2016 06 13 capture.JPG\"\r\nContent-Type: image/jpeg\r\n">]

in my create, I have the following

 @image_data = TempDatum.last       if @image_data.present?         # params[:images] = @image_data.data         params[:images] =  '[#<ActionDispatch::Http::UploadedFile:0xe4a46e8 @tempfile=#<Tempfile:C:/Users/cmendla/AppData/Local/Temp/RackMultipart20160614-13124-iib9h0.JPG>, @original_filename="2016 06 13 capture.JPG", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"images[]\"; filename=\"2016 06 13 capture.JPG\"\r\nContent-Type: image/jpeg\r\n">]'         $temp1 = 'got here'       end  

I have tried various ways of trying to get the contents of TempDatum.data into the params[:images] The way it is now, I was simply trying to take the raw data from the data field in the table.

What do I need to do to set params[:images] to the values in TempDatum.data for a given record.

Cannot update user profile with update_attributes

Posted: 14 Jun 2016 08:19 AM PDT

For the life of me I have no idea what is going on. I am using Rails 5 with React. I cant seem to update my profile.

Update Route:

/users/:user_id/profile(.:format)   profiles#update  

In my react component, the form is:

<form data-abide="" encType="multipart/form-data" action={url} method="patch">    <input type="text" name="profile[first_name]" value={this.state.firstName}/>    <button className="button expanded" type="submit">Update</button>  </form>  

If I set the form method to "post", it goes to the create method and replace the columns which I do not need that so I changed it to patch.

Profile controller:

...  skip_before_filter  :verify_authenticity_token # The only way to get this to work with React      def create    @profile = current_user.build_profile(profile_params)    if @profile.save     #...    else     #...    end  end    def update    @profile = current_user.profile    if @profile.update_attributes(profile_params)      #...    else      #...    end  end    private   def profile_params    params.require(:profile).permit(:first_name)   end    ...  

Is there something wrong?

Edit:

I get it to work, I set the form method to post then:

def create    update  end  

Is there a way to get the form to call the update method directly? As in comments, forms only supports GET/POST and not PATCH.

Serialized fields_for not populating from db on edit

Posted: 14 Jun 2016 07:59 AM PDT

On the edit page for this form all of the fields outside of the fields_for tag (inbox name, automatic reconciliation, and a few others not listed here) are all populating based on their corresponding db value. However, everything inside the fields_for tag are not, even though they're posting to the db just fine.

I posted :group_member_roles as an example but there are a few other fields inside their own other fields_for that are doing the same thing. It's just confusing that it will post to the db but not display on edit.

The more I read into fields_for the more I feel like I'm not using it correctly. It seems to be more inclined to populating db tables outside of the one your form is currently referencing, but I'm just trying to serialize data within the inbox table. When I look at the :group_member_roles column I want it to be an array/hash containing process true/false, action add/delete, and a string of values.

#_form.html.erb    <%= form_for(@inbox) do |f| %>      <%= f.label :inbox_name %>      <%= f.text_field :name, placeholder: "Inbox Name" %>    <%= f.label :automatic_reconciliation, "Turn on/off automatic reconciliation" %>    <div class="switch small">      <%= f.check_box :automatic_reconciliation, class: "switch-input" %>      <label class="switch-paddle" for="inbox_automatic_reconciliation">        <span class="show-for-sr">Automatic reconciliation</span>        <span class="switch-active" aria-hidden="true">On</span>        <span class="switch-inactive" aria-hidden="true">Off</span>      </label>    </div>    <%= f.fields_for :group_member_roles do |group_member_roles| %>    <h4>Group Member Roles</h4>    <%= group_member_roles.label :process, "Turn On/Off Processing" %>    <div class="switch small">      <%= group_member_roles.check_box :process, class: "switch-input" %>      <label class="switch-paddle" for="inbox_group_member_roles_process">        <span class="show-for-sr">Group Member Roles Processing</span>        <span class="switch-active" aria-hidden="true">On</span>        <span class="switch-inactive" aria-hidden="true">Off</span>      </label>    </div>      <%= group_member_roles.label :action, class: "hide" %>    <%= group_member_roles.select :action, ["Add", "Delete"], { selected: "Add" }, { class: "hide" } %>      <%= group_member_roles.label :values %>    <%= group_member_roles.text_field :values, placeholder: "1234, 1337, 1986" %>    <% end %>  

Thanks in advance for any help or guidance.

dynamic dropdown in rails based on string select

Posted: 14 Jun 2016 06:50 AM PDT

I have a drop down menu:

<div class="form-group">    <label for="usr">Degree Type:</label>    <%= f.select(:degreetype, options_for_select([['Bachelor Degree'],['Masters Degree'],['PHD']]),{}, {class:"form-control"})%>  </div>  

Based on the selection above I want the different dropdown

#if Bachelor Degree selected  <div class="form-group">    <label for="usr">level:</label>    <%= f.select(:level, options_for_select([['1st'],['2.1'],['2.2'],['3rd']]),{}, {class:"form-control"})%>  </div>    #if Master Degree selected  <div class="form-group">    <label for="usr">level:</label>    <%= f.select(:level, options_for_select([['1st'],['2.1'],['2.2'],['3rd']]),{}, {class:"form-control"})%>  </div>  

:degreetype is a string datatype.

Re-rendering Rails partial AFTER saving the model through a form

Posted: 14 Jun 2016 08:17 AM PDT

I'm re-rendering a partial after submitting a remote: true form, but my problem is that it seems to re-render the partial BEFORE fully completing the form's update action. As a result, it renders old data on the page, and shows updated info only after a full refresh (or when I submit the form yet again). Is there a way to force the application to re-render the partial after everything is completed, in order to display only the new info? Or am I missing a step here?

update.js.erb:

$("#methods").html("<%= escape_javascript(render partial: 'methods') %>");  

owner_controller.rb

respond_to :html, :js, :json    def update    if owner.update_attributes(owner_params)      respond_to do |format|        format.js      end    else      fail_update    end  end  

Rails Index Path Helper

Posted: 14 Jun 2016 06:38 AM PDT

I have the following in my BioContent controller:

  def index      unless (can? :read_index, BioContent) || (can?(:read_json, BioContent) && request.format == 'json')        raise CanCan::AccessDenied.new("Not authorized!", :read, BioContent)      end      content_type_slug = request.params[:content_type]      if content_type_slug.present?        @bio_contents = BioContent.includes(:content_type, :bio_asset).where(content_type: ContentType.find_by(slug: content_type_slug))      else        @bio_contents = BioContent.includes(:content_type, :bio_asset)      end      @actions = [:show, :edit, :destroy]    end  

And I'm trying to use the following path helper to get to the BioContent index page:

= render_dashboard_box_link_only 'Edit Bio Narrative', bio_content_path, 'panel-tile-alt-2'  

I want to create new functionality so the BioContent index page displays only the BioContents for a specific user. Currently, the BioContent index page is only accessed by admins who can see all the BioContents for all users. I need to maintain this functionality while also creating existing functionality where a user can log in and see only their BioContents.

Not sure if this helps, but this is the current path that admins use to see all the BioContents for all users:

/admin/bio_contents?content_type=bio_narrative  

Any help is greatly appreciated, I'm stuck.

Rails custom query data export

Posted: 14 Jun 2016 06:37 AM PDT

I am trying to export the data through rails to excel, but have a slight problem. When you go to the show.html.erb, it automatically displays the last 24 records from Reviews table. I have datetime selector on the same page to query to get the data from Reviews table as per datetime lookup. Excel/CSV export works fine for the last 24 records, but as soon as I conduct custom query through datetime selector and click on Export to xls, I still get last 24 records exported. I pretty well understand that respond_to code refreshes the controller after query and it considers that params are blank, which is the reason I am always getting last 24 records exported.

I want to export the data after custom query (through datetime query).

Does this make sense? Your kind assitance will be appreciated.

My controller code: review_controller.rb

if params[:date_from].blank? && params[:date_to].blank?    @data = Reviews.last(24).order(date_time: :desc)  elsif    @date_from = params[:date_from]    @date_to = params[:date_to]    @data = Reviews.where("date_time >= ? AND date_time <= ?", @date_from, @date_to).order(date_time: :desc)  end  respond_to do |format|    format.html    format.csv { send_data @data.to_csv }    format.xls { send_data @data.to_csv(col_sep: "\t") }  end  end  

View: show.html.erb

<%= form_tag(review_path, :method => "get")  do %>    <%= label_tag :date_from, 'From:' %>    <%= text_field_tag :date_from, @date_from, :id => 'datetimepicker1' %>    <%= label_tag :date_to, 'To:' %>    <%= text_field_tag :date_to, @date_to, :id => 'datetimepicker2' %>    <%= button_tag :Update, class: 'btn btn-info' %>  <% end %>`  

Model: review.rb

def self.to_csv(options = {})    CSV.generate(options) do |csv|      csv << column_names      all.each do |products|        csv << products.attributes.values_at(*column_names)      end    end  end  

Private_pub installing in Mac OS X 10.11 - Failed to build gem native extension for http_parser.rb

Posted: 14 Jun 2016 06:55 AM PDT

I try to install private_pub in my Rails 4 app. When I run bundle install I got such problem:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.        /Users/serj/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20160614-8815-15skczg.rb extconf.rb  creating Makefile    make "DESTDIR=" clean    make "DESTDIR="  compiling ruby_http_parser.c  couldn't understand kern.osversion `15.5.0'  In file included from /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/ruby.h:29,                   from /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby.h:33,                   from ruby_http_parser.c:1:  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/defines.h:26:19: error: stdio.h: No such file or directory  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/defines.h:28:24: error: sys/types.h: No such file or directory  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/defines.h:31:23: error: sys/stat.h: No such file or directory  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/defines.h:34:21: error: stdlib.h: No such file or directory  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/defines.h:45:21: error: string.h: No such file or directory  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/defines.h:48:22: error: strings.h: No such file or directory  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/defines.h:51:23: error: inttypes.h: No such file or directory  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/defines.h:54:21: error: stdint.h: No such file or directory  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/defines.h:57:21: error: unistd.h: No such file or directory  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/defines.h:61:25: error: sys/select.h: No such file or directory  In file included from /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/defines.h:68,                   from /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/ruby.h:29,                   from /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby.h:33,                   from ruby_http_parser.c:1:  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/missing.h:23:45: error: math.h: No such file or directory  In file included from /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/ruby.h:187,                   from /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby.h:33,                   from ruby_http_parser.c:1:  /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/../lib/gcc/i686-apple-darwin11/4.2.1/include/limits.h:10:25: error: limits.h: No such file or directory  In file included from /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:35,                   from /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/ruby.h:1710,                   from /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby.h:33,                   from ruby_http_parser.c:1:  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/st.h:142: error: expected declaration specifiers or '...' before 'uint32_t'  In file included from /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/ruby.h:1710,                   from /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby.h:33,                   from ruby_http_parser.c:1:  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:353: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rb_fdset_t'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:454: error: expected declaration specifiers or '...' before 'rb_fdset_t'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:454: error: expected declaration specifiers or '...' before 'rb_fdset_t'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:454: error: expected declaration specifiers or '...' before 'rb_fdset_t'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:454: warning: 'struct timeval' declared inside parameter list  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:454: warning: its scope is only this definition or declaration, which is probably not what you want  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:455: warning: 'struct timeval' declared inside parameter list  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:560: error: expected declaration specifiers or '...' before 'mode_t'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:639: error: expected declaration specifiers or '...' before 'pid_t'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:643: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rb_waitpid'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:644: error: expected ')' before 'pid'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:645: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rb_spawn'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:646: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rb_spawn_err'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:648: error: expected ')' before 'pid'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:763: error: expected declaration specifiers or '...' before 'uint32_t'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:912: error: expected ')' before 'long'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/intern.h:913: error: expected ')' before 'long'  In file included from /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby.h:33,                   from ruby_http_parser.c:1:  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/ruby.h:1758: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rb_event_flag_t'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/ruby.h:1759: error: expected ')' before 'evflag'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/ruby.h:1762: error: expected ')' before 'func'  /Users/serj/.rvm/rubies/ruby-2.2.1/include/ruby-2.2.0/ruby/ruby.h:1763: error: expected ')' before 'func'  In file included from ruby_http_parser.c:3:  ryah_http_parser.h:209: error: expected specifier-qualifier-list before 'uint32_t'  ryah_http_parser.h:265: error: expected specifier-qualifier-list before 'uint16_t'  ruby_http_parser.c: In function 'ParserWrapper_init':  ruby_http_parser.c:44: error: 'ryah_http_parser' has no member named 'status_code'  ruby_http_parser.c:45: error: 'ryah_http_parser' has no member named 'http_major'  ruby_http_parser.c:46: error: 'ryah_http_parser' has no member named 'http_minor'  ruby_http_parser.c: In function 'ParserWrapper_free':  ruby_http_parser.c:77: warning: implicit declaration of function 'free'  ruby_http_parser.c: In function 'on_message_begin':  ruby_http_parser.c:102: error: 'ryah_http_parser' has no member named 'data'  ruby_http_parser.c:104: warning: implicit declaration of function 'strlen'  ruby_http_parser.c:104: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:106: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:108: warning: ISO C90 forbids mixed declarations and code  ruby_http_parser.c: In function 'on_url':  ruby_http_parser.c:125: error: 'ryah_http_parser' has no member named 'data'  ruby_http_parser.c: In function 'on_header_field':  ruby_http_parser.c:131: error: 'ryah_http_parser' has no member named 'data'  ruby_http_parser.c: In function 'on_header_value':  ruby_http_parser.c:144: error: 'ryah_http_parser' has no member named 'data'  ruby_http_parser.c:146: warning: ISO C90 forbids mixed declarations and code  ruby_http_parser.c:160: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:162: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:167: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:169: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:172: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c: In function 'on_headers_complete':  ruby_http_parser.c:190: error: 'ryah_http_parser' has no member named 'data'  ruby_http_parser.c:192: warning: ISO C90 forbids mixed declarations and code  ruby_http_parser.c: In function 'on_body':  ruby_http_parser.c:211: error: 'ryah_http_parser' has no member named 'data'  ruby_http_parser.c:213: warning: ISO C90 forbids mixed declarations and code  ruby_http_parser.c: In function 'on_message_complete':  ruby_http_parser.c:230: error: 'ryah_http_parser' has no member named 'data'  ruby_http_parser.c:232: warning: ISO C90 forbids mixed declarations and code  ruby_http_parser.c: In function 'Parser_alloc_by_type':  ruby_http_parser.c:262: error: 'ryah_http_parser' has no member named 'data'  ruby_http_parser.c: In function 'Parser_execute':  ruby_http_parser.c:314: warning: ISO C90 forbids mixed declarations and code  ruby_http_parser.c:320: warning: ISO C90 forbids mixed declarations and code  ruby_http_parser.c:322: error: 'ryah_http_parser' has no member named 'upgrade'  ruby_http_parser.c: In function 'Parser_upgrade_p':  ruby_http_parser.c:381: error: 'ryah_http_parser' has no member named 'upgrade'  ruby_http_parser.c: In function 'Parser_http_version':  ruby_http_parser.c:388: error: 'ryah_http_parser' has no member named 'http_major'  ruby_http_parser.c:388: error: 'ryah_http_parser' has no member named 'http_minor'  ruby_http_parser.c:391: error: 'ryah_http_parser' has no member named 'http_major'  ruby_http_parser.c:391: error: 'ryah_http_parser' has no member named 'http_minor'  ruby_http_parser.c: In function 'Parser_http_major':  ruby_http_parser.c:398: error: 'ryah_http_parser' has no member named 'http_major'  ruby_http_parser.c:398: error: 'ryah_http_parser' has no member named 'http_minor'  ruby_http_parser.c:401: error: 'ryah_http_parser' has no member named 'http_major'  ruby_http_parser.c: In function 'Parser_http_minor':  ruby_http_parser.c:408: error: 'ryah_http_parser' has no member named 'http_major'  ruby_http_parser.c:408: error: 'ryah_http_parser' has no member named 'http_minor'  ruby_http_parser.c:411: error: 'ryah_http_parser' has no member named 'http_minor'  ruby_http_parser.c: In function 'Parser_http_method':  ruby_http_parser.c:419: error: 'ryah_http_parser' has no member named 'method'  ruby_http_parser.c:419: error: 'ryah_http_parser' has no member named 'method'  ruby_http_parser.c:419: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:419: error: 'ryah_http_parser' has no member named 'method'  ruby_http_parser.c:419: error: 'ryah_http_parser' has no member named 'method'  ruby_http_parser.c: In function 'Parser_status_code':  ruby_http_parser.c:428: error: 'ryah_http_parser' has no member named 'status_code'  ruby_http_parser.c:429: error: 'ryah_http_parser' has no member named 'status_code'  ruby_http_parser.c: In function 'Parser_set_header_value_type':  ruby_http_parser.c:451: warning: ISO C90 forbids mixed declarations and code  ruby_http_parser.c: In function 'Init_ruby_http_parser':  ruby_http_parser.c:473: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:474: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:475: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:476: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:477: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:478: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:479: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:481: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:482: warning: incompatible implicit declaration of built-in function 'strlen'  ruby_http_parser.c:483: warning: incompatible implicit declaration of built-in function 'strlen'  make: *** [ruby_http_parser.o] Error 1    make failed, exit code 2    Gem files will remain installed in /Users/serj/.rvm/gems/ruby-2.2.1@email_platform/gems/http_parser.rb-0.6.0 for inspection.  Results logged to /Users/serj/.rvm/gems/ruby-2.2.1@email_platform/extensions/x86_64-darwin-13/2.2.0/http_parser.rb-0.6.0/gem_make.out  An error occurred while installing http_parser.rb (0.6.0), and Bundler cannot continue.  Make sure that `gem install http_parser.rb -v '0.6.0'` succeeds before bundling.  

How can I fix that?

enqueuing jobs using sucker punch

Posted: 14 Jun 2016 06:43 AM PDT

I have one doubt with enqueuing the job using sucker punch.

I have 2000+ search keywords in my database I want to know the google and bing ranking for each keyword in my database. For this I'm using Authority Labs API. But AuthorityLabs will only process 1000 POST request in 1 hour. I'm sending each request to AuthorityLab as a background job using sucker punch. How can I limit only 1000 jobs will run in 1 hour, remaining jobs only start after one hour. Also I want to run this jobs daily for analysing the rank change.

How to create a route to a controller method which is called by a POST AJAX request

Posted: 14 Jun 2016 06:41 AM PDT

I am trying to figure out how to create a route to a controller method which is called by a POST ajax request in jQuery. I have a function that uses AJAX to update the setup time, which receives data from a select_tag. Here is the following code for that method:

    ,update_setup_time: function(e) {      var d = $('#setup_form_popup').val();      $.ajax({          url: '/events/update_setup_time_p',          type: 'POST',          dataType: 'json',          data: d,          success: function() {              alert(d + "how are you doing?");          }      });  }  

I want the URL to call the method update_setup_time_p, which is a method in the controller. However, how do I route to this within the route.rb file? Any and all help is appreciated.

Rails + Cocoon: update nested resource instead of destroy it

Posted: 14 Jun 2016 07:01 AM PDT

My current Cocoon / nested form works very well. However I would like to change this behavior:

Main model:

accepts_nested_attributes_for :varietals, :reject_if => lambda { |a| a[:grape_id].blank? && a[:id].blank? }, allow_destroy: true  

Instead of deleting the varietal object with allow_destroy, I want to update its status field to 0 when it is destroyed.

It is possible to call a function in this line to do that ? Should I update the varietal model instead ?

Something like:

varietal.update_attributes(:status => 0)  

when one nested resource is deleted by the user.

Thanks.

EDIT: data post after an edit of the main form and the removing of a nested varietal to help:

"varietals_attributes"=>{"0"=>{"grape_attributes"=>{"id"=>"168"}, "grape_id"=>"168", "percent"=>"20", "_destroy"=>"1", "id"=>"32709368-3496-47EA-A386-B1CCECA0BAEF"}},  

Rails: Missing helper file post_comments_helper.rb_helper.rb/Unitialized constant C Error Message

Posted: 14 Jun 2016 06:15 AM PDT

I'm trying to run my tests in rails but whenever I do I get this error:

C:/Ruby22/lib/ruby/gems/2.2.0/gems/actionpack-4.2.6/lib/abstract_controller/helpers.rb:151:in `rescue in block in modules_for_helpers': Missing helper file helpers/c:/users/adamg/desktop/baseball_blog/app/helpers/post_comments_helper.rb_helper.rb (AbstractController::Helpers::MissingHelperError)  

This makes no sense because it doubles the helper.rb at the end of the helper file. I noticed that in the error message it shows that my Users file is lowercase, but on my pc it's uppercase, I was wondering if this could possibly be part of the problem? Also I can run my rails server n problem with everything working perfectly, so I'm certain that it has to be a problem with something in my tests and not my actual project files. This is my rails_helper.rb file:

  # This file is copied to spec/ when you run 'rails generate rspec:install'  ENV['RAILS_ENV'] ||= 'test'  require File.expand_path('../../config/environment', __FILE__)  # Prevent database truncation if the environment is production  abort("The Rails environment is running in production mode!") if Rails.env.production?  require 'spec_helper'  require 'rspec/rails'  require 'capybara/rails'  require 'capybara/rspec'  require 'factory_girl'    # Add additional requires below this line. Rails is not loaded until this point!    # Requires supporting ruby files with custom matchers and macros, etc, in  # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are  # run as spec files by default. This means that files in spec/support that end  # in _spec.rb will both be required and run as specs, causing the specs to be  # run twice. It is recommended that you do not name files matching this glob to  # end with _spec.rb. You can configure this pattern with the --pattern  # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.  #  # The following line is provided for convenience purposes. It has the downside  # of increasing the boot-up time by auto-requiring all files in the support  # directory. Alternatively, in the individual `*_spec.rb` files, manually  # require only the support files necessary.  #  Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }    # Checks for pending migration and applies them before tests are run.  # If you are not using ActiveRecord, you can remove this line.  ActiveRecord::Migration.maintain_test_schema!    RSpec.configure do |config|    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures    config.fixture_path = "#{::Rails.root}/spec/fixtures"            # This file is copied to spec/ when you run 'rails generate rspec:install'  ENV['RAILS_ENV'] ||= 'test'  require File.expand_path('../../config/environment', __FILE__)  # Prevent database truncation if the environment is production  abort("The Rails environment is running in production mode!") if Rails.env.production?  require 'spec_helper'  require 'rspec/rails'  require 'capybara/rails'  require 'capybara/rspec'  require 'factory_girl'    # Add additional requires below this line. Rails is not loaded until this point!    # Requires supporting ruby files with custom matchers and macros, etc, in  # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are  # run as spec files by default. This means that files in spec/support that end  # in _spec.rb will both be required and run as specs, causing the specs to be  # run twice. It is recommended that you do not name files matching this glob to  # end with _spec.rb. You can configure this pattern with the --pattern  # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.  #  # The following line is provided for convenience purposes. It has the downside  # of increasing the boot-up time by auto-requiring all files in the support  # directory. Alternatively, in the individual `*_spec.rb` files, manually  # require only the support files necessary.  #  Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }    # Checks for pending migration and applies them before tests are run.  # If you are not using ActiveRecord, you can remove this line.  ActiveRecord::Migration.maintain_test_schema!    RSpec.configure do |config|    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures    config.fixture_path = "#{::Rails.root}/spec/fixtures"      # If you're not using ActiveRecord, or you'd prefer not to run each of your    # examples within a transaction, remove the following line or assign false    # instead of true.    config.use_transactional_fixtures = true    config.include RailsDomIdHelper, type: :feature    config.include PostHelpers, type: :feature    config.include UsersHelpers, type: :feature      # RSpec Rails can automatically mix in different behaviours to your tests    # based on their file location, for example enabling you to call `get` and    # `post` in specs under `spec/controllers`.    #    # You can disable this behaviour by removing the line below, and instead    # explicitly tag your specs with their type, e.g.:    #    #     RSpec.describe UsersController, :type => :controller do    #       # ...    #     end    #    # The different available types are documented in the features, such as in    # https://relishapp.com/rspec/rspec-rails/docs    config.infer_spec_type_from_file_location!      # Filter lines from Rails gems in backtraces.    config.filter_rails_from_backtrace!    # arbitrary gems may also be filtered via:    # config.filter_gems_from_backtrace("gem name")  end    Shoulda::Matchers.configure do |config|    config.integrate do |with|      with.test_framework :rspec      with.library :rails    end      RSpec.configure do |config|      config.include FactoryGirl::Syntax::Methods    end  end  

This is my spec_helper file:

    # This file was generated by the `rails generate rspec:install` command. Conventionally, all  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.  # The generated `.rspec` file contains `--require spec_helper` which will cause  # this file to always be loaded, without a need to explicitly require it in any  # files.  #  # Given that it is always loaded, you are encouraged to keep this file as  # light-weight as possible. Requiring heavyweight dependencies from this file  # will add to the boot time of your test suite on EVERY test run, even for an  # individual file that may not need all of that loaded. Instead, consider making  # a separate helper file that requires the additional dependencies and performs  # the additional setup, and require it from the spec files that actually need  # it.  #  # The `.rspec` file also contains a few flags that are not defaults but that  # users commonly want.  #  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration  RSpec.configure do |config|    # rspec-expectations config goes here. You can use an alternate    # assertion/expectation library such as wrong or the stdlib/minitest    # assertions if you prefer.    config.expect_with :rspec do |expectations|      # This option will default to `true` in RSpec 4. It makes the `description`      # and `failure_message` of custom matchers include text for helper methods      # defined using `chain`, e.g.:      #     be_bigger_than(2).and_smaller_than(4).description      #     # => "be bigger than 2 and smaller than 4"      # ...rather than:      #     # => "be bigger than 2"      expectations.include_chain_clauses_in_custom_matcher_descriptions = true    end      # rspec-mocks config goes here. You can use an alternate test double    # library (such as bogus or mocha) by changing the `mock_with` option here.    config.mock_with :rspec do |mocks|      # Prevents you from mocking or stubbing a method that does not exist on      # a real object. This is generally recommended, and will default to      # `true` in RSpec 4.      mocks.verify_partial_doubles = true    end    # The settings below are suggested to provide a good initial experience  # with RSpec, but feel free to customize to your heart's content.  =begin    # These two settings work together to allow you to limit a spec run    # to individual examples or groups you care about by tagging them with    # `:focus` metadata. When nothing is tagged with `:focus`, all examples    # get run.    config.filter_run :focus    config.run_all_when_everything_filtered = true      # Allows RSpec to persist some state between runs in order to support    # the `--only-failures` and `--next-failure` CLI options. We recommend    # you configure your source control system to ignore this file.    config.example_status_persistence_file_path = "spec/examples.txt"      # Limits the available syntax to the non-monkey patched syntax that is    # recommended. For more details, see:    #   - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/    #   - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/    #   - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode    config.disable_monkey_patching!      # This setting enables warnings. It's recommended, but in some cases may    # be too noisy due to issues in dependencies.    config.warnings = true      # Many RSpec users commonly either run the entire suite or an individual    # file, and it's useful to allow more verbose output when running an    # individual spec file.    if config.files_to_run.one?      # Use the documentation formatter for detailed output,      # unless a formatter has already been configured      # (e.g. via a command-line flag).      config.default_formatter = 'doc'    end      # Print the 10 slowest examples and example groups at the    # end of the spec run, to help surface which specs are running    # particularly slow.    config.profile_examples = 10      # Run specs in random order to surface order dependencies. If you find an    # order dependency and want to debug it, you can fix the order by providing    # the seed, which is printed after each run.    #     --seed 1234    config.order = :random      # Seed global randomization in this process using the `--seed` CLI option.    # Setting this allows you to use `--seed` to deterministically reproduce    # test failures related to randomization by passing the same `--seed` value    # as the one that triggered the failure.    Kernel.srand config.seed  =end  end  

I don't have any helpers in my PostComments module and so therefore I haven't tested anything inside of the spec file.

When I do add the post_comments_helper.rb_helper.rb file I get this error message:

C:/Ruby22/lib/ruby/gems/2.2.0/gems/activesupport-4.2.6/lib/active_support/inflector/methods.rb:261:in `const_get': uninitialized constant C (NameError)  

Any help would be greatly appreciated!

undefined method `trigger' for Pusher:Module

Posted: 14 Jun 2016 05:48 AM PDT

I am just getting started with the pusher

In config/initializers/pusher.rb

require 'pusher'    Pusher.app_id = 'xxx'  Pusher.key = 'xxx'  Pusher.secret = 'xxx'  Pusher.logger = Rails.logger  Pusher.encrypted = true  

In the application.html.erb

// Enable pusher logging - don't include this in production  Pusher.logToConsole = true;    var pusher = new Pusher('xxx', {    encrypted: true  });    var channel = pusher.subscribe('test_channel');  channel.bind('my_event', function(data) {    alert(data.message);  });  

In the controller

require 'pusher'

class CheckPushController < ApplicationController    def show      Pusher.trigger('test_channel', 'my_event', {        message: 'hello world'      })    end  end  

I used the same, in the dashboard I was able to send a trigger to test_channel. However when reloaded the page, I am getting

undefined method `trigger' for Pusher:Module  

document.ready not working when clicked on anchor

Posted: 14 Jun 2016 06:49 AM PDT

I have the navigation menu with <a>tags.

Now if I reload the page using browser refresh button, jQuery dom ready($(document).ready(function() {}) method is being invoked.

But if I click on navigation links, that time jQuery dom ready($(document).ready(function() {}) method is not invoked.

If it helps in any way, I'm using Ruby on Rails as a framework.

This is how my application.js looks like:

  //= require jquery    //= require_tree  

No comments:

Post a Comment