I'm running a rails app on heroku and recently switched to cloudflare for CDN for asset serving. My understanding was that once I use cloudflare, my assets (ie js,css,images) would be served from cloudflare and not from my own server but in my heroku logs I still see the requests for assets. Do I need to configure something in my rails app like setting the asset_host or something? Thanks.
vendredi 8 mai 2015
Validations, Nested Attributes and error handling when parent model isn't valid
Recently I added validations to one of the models in my application, and this seems to have caused a somewhat strange behaviour that I'm not handling properly in my code.
Here's a hypothetical example:
Clients
# name: string, phone: string, address: string
class Client < ActiveRecord::Base
has_many :transactions
accepts_nested_attributes_for :transaction, allow_destroy: true
validate :phone, numericality: true
end
Transactions
# p_date: date, location_id: integer
class Transaction < ActiveRecord::Base
belongs_to :client
end
This is how the controller would look like (again, have in mind that this is hypothetical):
PurchasesController
before_action :set_client, only: [:show, :edit, :update, :destroy]
def update
respond_to do |format|
if @client.update(client_params)
format.html { redirect_to clients_path, notice: 'Updated Succesfully' }
format.json { render :show, status: :ok, location: @client }
else
format.html { render :edit }
format.json { render json: @client.errors, status: :unprocessable_entity }
end
end
end
def client_params
params.require(:client).permit(
:name, :phone, :address,
transaction_attributes: [:id, :p_date, :location_id, :_destroy]
)
end
def set_client
@client = Client.find(params[:id])
end
For new records this works fine, but when I run into old ones that do not conform to the new validation rules in the phone number, the nested attributes aren't saved, because it's parent record is no longer valid.
I'm trying to find a way how to handle such errors.
Currently, this would be handled by the else condition in if @client.update(client_params) in the controller. When an error happens, the controller renders the :edit action, which results in another error in my view, cause now the helper that generates the fields for the nested form is receiving a null value for @client.
The view in question that generates the error looks like this:
purchases/:client_id/edit.html.haml
= form_for @client, :url => {:controller => 'purchase', :action => 'update'} do |f|
- if @client.errors.any?
#error_explanation
%h2
The following errors were found:
%ul
- @client.errors.full_messages.each do |message|
%li= message
=render 'form', f: f
.actions
=f.submit 'Save Changes', :class => 'btn btn-md btn-primary'
The error says: "First argument in form cannot contain nil or be empty", which I'm assuming it is cause the render is not sending the id of the Client.
In case you're wondering, I'm using form_for @client, :url => {:controller => 'purchase', :action => 'update'} do |f| cause this view is not in the Client controller. if I omit the extra parameters, the form is sent directly to the Client controller, which has different code pertaining only to the Client model.
I've partially managed to work around this by using the following in the update action:
def update
respond_to do |format|
if @client.update(client_params)
# *snip*
else
format.html { redirect_to edit_purchase_path(@client) }
format.json { render json: @client.errors, status: :unprocessable_entity }
end
end
end
This will redirect me back to the edit action, but no errors are printed. I get an identical page with the values used before I edited the values of the Transaction. I'm think there must be an easy way to send the errors back to the view, but I'm not sure where are these supposed to be used.
The "original" controller was generated by a scaffold, so the render :edit part is from the scaffolding itself. I'm aware my example could be somewhat vague (I'm just transcribing what I'm experiencing), so bear with me if this sounds a little odd. I'll gladly go into more detail if the information provided isn't enough.
What does this code, that looks like JavaScript object do?
@options = { query: {site: service, page: page} }
What does this do? In javascript this, I think would be object definition, however I cannot find what exactly it is in ruby. This would be the full code:
class StackExchange
include HTTParty
base_uri 'api.stackexchange.com'
def initialize(service, page)
@options = { query: {site: service, page: page} }
end
def questions
self.class.get("/2.2/questions", @options)
end
def users
self.class.get("/2.2/users", @options)
end
end
will_paginate: can't figure out how to customize inside bullets
I am trying to make a custom page list using will_paginate. I have succesfully created the previous and next buttons. I'm now trying to create the buttons in between but a having trouble figuring out how.
Here is my code for the previous and next buttons:
<ul class="pagination-styler">
<% if @options.previous_page %>
<li>
<%= link_to params.merge(:page => @options.previous_page), style: "aria-label: previous;" do %>
<i class="ba ba-left"></i>
<% end %>
</li>
<% end %>
Page <%= @options.current_page %> of <%= @options.total_pages %>
<% if @options.next_page %>
<li>
<%= link_to params.merge(:page => @options.next_page ), "aria-label" => "next" do %>
<i class="ba ba-right"></i>
<% end %>
</li>
<% end %>
</ul>
This renders the following:
I want to replace where it says "page 2 of 3" with icons I have that look similar to the previous and next buttons and will have specific page numbers. I can't find any helpers or way of doing this provided by will_paginate, but i'm sure there must be a way.
Does anyone know how to customize the actual link buttons? I'll need to wrap them in "li" and add the inside the links.
Rails 4 Internationalization I18n
My Rails App is on rails 4.0.2 and I have a problem switching translations with the locale variable and the params[:locale] from the url scheme following the official rails guide. I have a single page website at my site.
My routes for Internationalization:
scope "(:locale)", locale: /en|de/ do
#my routes here
end
My application controller
before_filter :set_locale
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
#Rails.application.routes.default_url_options[:locale]= I18n.locale
end
# app/controllers/application_controller.rb
def default_url_options(options = {})
{ locale: I18n.locale }.merge options
end
The links to change the locale variables in the view:
<%= link_to_unless I18n.locale == :en, "English", locale: :en %>
|
<%= link_to_unless I18n.locale == :de, "Deutsch", locale: :de %>
What happens: the locale variable is set correctly but the translations are not switching. If I remove one of the translation files (currently for english and german) the languages switches to the remaining translation file. When I put back the other translation file and try to switch to it by changing the locale variable it never switches to the other language.
Why is my code not changing the translations?
How to remove bullet point when printing errors that are tied to base in rails 4 application?
I have a custom validator in a ROR 4 app which checks for a condition and then adds a custom error message to base:
errors.add(:base, "Please enter email as well as your city")
When the error displays on the screen, it has a bullet point in it. Can I remove the bullet point as the error is for the whole form and not a particular field? I do not want a generic css rule which removes bullet points from all errors added to base across the app. Is this possible? Thank you for your help.
Rails delete functionality is not working
I am completely new to Ruby On Rails, and going through this guide to build a basic application.
When I am trying to implement the delete functionality as mentioned in the document, I am seeing the show page.
I have below method in my controller:
def destroy
@article = Article.find(params[:id])
@article.destroy
redirect_to articles_path
end
and below line in my page:
<td><%= link_to 'Destroy', article_path(article),
method: :delete,
data: { confirm: 'Are you sure?' } %></td>
Now when I click on the link, I am seeing below URL in browser:
Now now in this case I am seeing the show screen instead of getting an alert message and then deleting the record from my page.
I have followed this SO post - Rails 4 link_to Destroy not working in Getting Started tutorial
and verified that
//= require jquery
//= require jquery_ujs
elements are there in my application.js
Please tell me where I am doing mistake?
outlook renders Rails mailer in opposite order
I have the following view associated with my mailer:
.my-div{:style=> "font-family:'Open Sans'"}
%img{:src=>"http://ift.tt/1EVgP3o", :style=>"float:right;width:50px;"}
%h1{:style => "font-size:18px;font-weight:700;font-family:'Open Sans';position:relative;top:70px;"}
Dear
-@first = @application.first_name.slice(0,1).capitalize + @application.first_name.slice(1..-1)
=@first
-@family = @application.family_name.slice(0,1).capitalize + @application.family_name.slice(1..-1)
#{@family},
Application ID:
=@application.id
%br
Date:
=@application.created_at.strftime("%m/%d/%Y")
%br
%br
Thank you for enrolling in one of FLS International Language Centres' programs.
What I don't understand is how the <h1>is rendered after the Date and ID information in Outlook, or for any mailer for that matter. Am I using the wrong mail extension or something?
Here is the Outlook rendered output:
Here is Gmail:
N.B. I know there is different content in each, but it is using the same html.haml view populated by my Ruby On Rails 4 Mailer.
Rails: Does a community standard exist on the proper indentation of options hashes?
I've noticed many developers are very careful to keep their code lines to as few characters as possible. With that in mind, is one of these formats for options hashes more widely used than the others by the Rails community? This list is not all-inclusive, most likely.
All one line:
@user = User.create(:user, firstname: 'Larry', lastname: 'Jones', position: 'Beekeeper', favorite_movie: 'Wicker Man', favorite_team: 'Hornets')
List after object:
@user = User.create(:user, firstname: 'Larry',
lastname: 'Jones',
position: 'Beekeeper',
favorite_movie: 'Wicker Man',
favorite_team: 'Hornets')
List under object:
@user = User.create(:user,
firstname: 'Larry',
lastname: 'Jones',
position: 'Beekeeper',
favorite_movie: 'Wicker Man',
favorite_team: 'Hornets')
List with less indentation:
@user = User.create(:user,
firstname: 'Larry',
lastname: 'Jones',
position: 'Beekeeper',
favorite_movie: 'Wicker Man',
favorite_team: 'Hornets')
ActiveRecord 'where' clause using function
I am trying to apply filters on an ActiveRecord::Relation. I would like to apply a 'where' clause (or the equivalent) to make the following call.
record = Record.all
record.where(record.remaing_units > 5)
I know this would be easy to get coding a fonction and passing it 2 arguments but I would like to know if there is a cleaner way to do it, more 'where' like.
EDIT : remaining_units is a method of Record class calculating subtraction between 2 fields.
subdomained Nginx Returns 403 forbidden for unicorn/rails setup
I am trying to route my subdomain to a digital ocean server running a rails app via nginx and unicorn. On some computers, the app loads fine. On others (and most) the site routes to the IP and returns nginx 403 error. It looks like this in the logs of /var/log/nginx/error.log: [error] 1618#0: *68 directory index of "path/to/app" is forbidden, client: 24.114.44.135, server: _,
Here is my /etc/nginx/nginx.conf file:
user **user**;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascrip$
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Deployer is the same user I'm (successfully) deploying with capistrano Here is the result of running ls -la at /var/www:
total 16
drwxrwx--- 4 deployer deployer 4096 Apr 23 14:40 .
drwxr-xr-x 13 775 www-data 4096 Apr 22 17:30 ..
drwxrwx--- 2 deployer deployer 4096 Apr 23 14:40 html
drwxrwxr-x 4 deployer deployer 4096 May 7 20:11 my_app_name
subfolders/files all seem to be owned by deployer and is the result of running:
chown -R deployer:deployer
I also have tried :
sudo chmod -R 755 /var/www
as suggested by some blogs/other questions..admittedly I'm sort of lost in commands and permissions now. My linux/production experience is pretty weak. I have a bunch of answers to the similar question including changing config to nginx user www-data and various combinations. The tailing error logs are various forms of *number directory forbidden. This error only started happening after I tried to move it from IP to subdomain.
Edit for /etc/nginx/sites-enabled/appstuff:
upstream unicorn_my_app_name_production {
server unix:/tmp/unicorn.my_app_name_production.sock fail_timeout=0;
}
server {
listen 80;
client_max_body_size 4G;
keepalive_timeout 10;
error_page 500 502 504 /500.html;
error_page 503 @503;
server_name sub.domain.com;
root path/to/public/folder;
autoindex on;
try_files $uri/index.html $uri @unicorn_my_app_name_production;
index index.html index.htm;
location @unicorn_my_app_name_production {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn_my_app_name_production;
# limit_req zone=one;
access_log /var/log/nginx/my_app_name_production.access.log;
error_log /var/log/nginx/my_app_name_production.error.log;
}
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location = /50x.html {
root html;
}
location = /404.html {
root html;
location @503 {
error_page 405 = /system/maintenance.html;
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html break;
}
rewrite ^(.*)$ /503.html break;
}
if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
return 405;
}
if (-f $document_root/system/maintenance.html) {
return 503;
}
}
Creating a migration to update a specific row of a table?
I have a migration that adds data:
{t: "test", v: [{loc: ["N"]}],
sub: [
{t: "D", v: [{loc: ["ssssss"]}, "^^"], ref: "datdat"},
{t: "D", v: [{loc: ["data"]}, "^^"], ref: "datas"}
,
...
I need to make a migration that updates this data.
How might one write a migration similar to "UPDATE sometable SET loc = 'BBB' WHERE loc = 'data'"
Browser forcing SSL even after I stopped asking it to force - cookie issue
I have updated my application with a line that says:
config.force_ssl = true
That made my website force all requests to https. But since I use iframes, that created a bunch of problems and I decided to rollback that line to think this through.
The problem is that all users that were impacted by my original change are now being redirected to SSL no matter the fact that I already commented that line out.
This is only fixed if I clean the cookies on the browser cache, which is definitely not something I can ask my users to do.
How can I fix this now? Any clues?
How to extract bike listings using information from 3taps API
Developing a Ruby on Rails app using information from the 3 taps API. The information I want is from Craigslist. Want to extract information on bikes for sale in the UK.
the following gives me the category information for bikes for sale
{
"code": "SBIK",
"group_code": "SSSS",
"group_name": "For Sale",
"name": "Bicycles"
},
so in my browser i add the following
{
"success": true,
"anchor": 2110058535,
"postings": [
{
"id": 2109916051,
"source": "CRAIG",
"category": "SBIK",
"external_id": "5010763041",
"external_url": "http://ift.tt/1EV9Yqu",
"heading": "WTB: Tri-bike...56-58cm",
"timestamp": 1430838700,
"annotations": {
"source_map_yahoo": "http://ift.tt/1JUka6W",
"source_continent": "USA",
"latlong_source": "In Posting",
"source_heading": "WTB: Tri-bike...56-58cm",
"source_cat": "sss",
"proxy_ip": "104.236.116.193:22225",
"source_state": "North Carolina",
"phone": "5010763041",
"source_account": "5hz2n-5010763041@sale.craigslist.org",
"gzip_data_size": "4170",
"source_loc": "wilmington",
"source_subcat": "bia|bik",
"html_data_size": "12631",
"source_map_google": "http://ift.tt/1EV9Yqw"
},
but when i add the country code -which is GBR i get nothing i have added http://ift.tt/1JUkbYz
but get error {"success":false,"error":"level params not supported in polling"}
when i do a location search it works using the metro field
"locations": [
{
"bounds_max_lat": 57.21864,
"bounds_max_long": -2.06182,
"bounds_min_lat": 57.10158,
"bounds_min_long": -2.22161,
"code": "GBR-ABD",
"full_name": "Aberdeen, United Kingdom",
"short_name": "Aberdeen"
},
{
"bounds_max_lat": null,
"bounds_max_long": null,
"bounds_min_lat": null,
"bounds_min_long": null,
"code": "GBR-BAT",
"full_name": "Bath, United Kingdom",
"short_name": "Bath"
},
but when i add this to my polling search , i cannot get this to return any values for bikes for sale in the uk?
also used &location.city=GBR-MAN to find bikes in manchester which returns error
i get {"success":false,"error":"level, country params not supported in polling"}.
Why it takes so long on Proc#call and API::Root#call
I am using Grape on top of Rails 4.2.1 to provide API for our application.
But when I check Newrelic for performance today I found that RackApp Proc#call and Grape API::Root#call are taking up large amount of time. (See the screenshot)
What actually are they doing? I figured that Grape API::Root#call is what my code is doing inside an API block, but what's RackApp Proc#call doing and why it takes up so much time? How could I know that?
Thanks a lot for the help.
Carrierwave file path stored in associated model
My structure
class Project
has_many :documents MyUploader
def directory
...
end
class Document
belongs_to :project
mount_uploader :physical_doc
def directory
folder = File.join(self.project.directory, self.class::SUBFOLDER)
Dir.mkdir(folder) unless File.exists?(folder)
folder
end
MyUploader
def store_dir
nil
end
def cache_dir
self.model.directory
end
The storage dir of my document is only known by the project (the location may change, and the Project class is responsible for moving docs in case)
The problem
When deleting a document, Rails will delete the "fields" in the order in which they appear in the code. That is to say
- It will first delete the
:projectassociation - Then it will delete the
mount_uploader :physical_doc - ... But the carrierwave mount_uploader needs to know where the file is stored in order to delete the file ! Oh oh.....
In other words, those two pieces of code are not equivalent
class Document mount_uploader :physical_doc belongs_to :project # This allows the document to be deleted, not created
class Document belongs_to :project mount_uploader :physical_doc # This allows the document to be created, not deleted
Solution ?
Best way to deal with an error caused by a method returning no values?
The following code is implemented to read in values and fill in a table with the appropriate values, however when one of the methods doesn't return anything it produces an error and crashes the page.
<tr class="event-row" >
<td><%= event.description %></td>
<td><%= event.contact.name %></td>
<td><%= event.start.strftime('%H:%M') %></td>
<td><%= event.end.strftime('%H:%M') %></td>
<td><%= link_to "edit", edit_event_path(event) %></td>
<td><%= link_to "delete", event, method: :delete, data: {confirm: "Are you sure?"} %>
<td><%= link_to "show", event_path(event) %></td>
</tr>
How can you check to see if the methods are returning no values?
ActiveModel::MissingAttributeError: can't write unknown attribute `user_id`
I am trying to implement a "comment" feature as part of my assignment for an project I am building.
Earlier in the course we created a comment table and had the Faker gem generate fake comments.
My instructions are as follows:
Comments must be associated with users, so add a user_id foreign key to the comments table. Remember to add an index to it too;
Update the User model so you can call user.comments, and the Comment model so you can call comment.user;
Modify the seeds.rb file to create valid comments when you run db:reset;
Initially I tried to run my rails generate commands but kept running into this error:
▶ rake db:migrate
== 20150508143445 CreateComments: migrating ===================================
-- create_table(:comments)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: table "comments" already exists: CREATE TABLE "comments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "description" text, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) /Users/jon/code/bloccit/db/migrate/20150508143445_create_comments.rb:3:in `change'
-e:1:in `<main>'
ActiveRecord::StatementInvalid: SQLite3::SQLException: table "comments" already exists: CREATE TABLE "comments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "description" text, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
/Users/jon/code/bloccit/db/migrate/20150508143445_create_comments.rb:3:in `change'
-e:1:in `<main>'
SQLite3::SQLException: table "comments" already exists
/Users/jon/code/bloccit/db/migrate/20150508143445_create_comments.rb:3:in `change'
-e:1:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
So I discovered that I needed to delete the old table from the start of the course. I did this in the console.
ActiveRecord::Base.connection.execute("drop table comments")
It seemed to work. I was then able to run these in terminal.
▶ rake db:migrate
== 20150508143445 CreateComments: migrating ===================================
-- create_table(:comments)
-> 0.0015s
== 20150508143445 CreateComments: migrated (0.0016s) ==========================
== 20150508152354 DropComments: migrating =====================================
== 20150508152354 DropComments: migrated (0.0000s) ============================
▶ rails g migration AddCommentToUsers commed_id:integer:index
invoke active_record
create db/migrate/20150508155200_add_comment_to_users.rb
▶ rake db:migrate
== 20150508155200 AddCommentToUsers: migrating ================================
-- add_column(:users, :commed_id, :integer)
-> 0.0010s
-- add_index(:users, :commed_id)
-> 0.0012s
== 20150508155200 AddCommentToUsers: migrated (0.0023s) =======================
models/comment.rb
class Comment < ActiveRecord::Base
belongs_to :user
end
models/user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
has_many :posts
has_many :comments
# CarrierWave method for attribute functionality
mount_uploader :avatar, AvatarUploader
# These methods check the role of a user in the database
def admin?
role == 'admin'
end
def moderator?
role == 'moderator'
end
end
migrations/create_comments.rb
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.text :description
t.timestamps null: false
end
end
end
migrations/add_comment_to_users.rb
class AddCommentToUsers < ActiveRecord::Migration
def change
add_column :users, :commed_id, :integer
add_index :users, :commed_id
end
end
In my seeds.rb I have changed
# Create Comments
50.times do
Comment.create!(
# user: users.sample, # we have not yet associated Users with Comments
post: posts.sample,
description: Faker::Lorem.paragraph
)
end
to
# Create Comments
50.times do
Comment.create!(
user: users.sample,
description: Faker::Lorem.paragraph
)
end
Now when I run rake db:reset I get this error.
▶ rake db:reset
-- create_table("advertisements", {:force=>:cascade})
-> 0.0047s
-- create_table("answers", {:force=>:cascade})
-> 0.0010s
-- add_index("answers", ["question_id"], {:name=>"index_answers_on_question_id"})
-> 0.0014s
-- create_table("comments", {:force=>:cascade})
-> 0.0010s
-- create_table("posts", {:force=>:cascade})
-> 0.0010s
-- add_index("posts", ["topic_id"], {:name=>"index_posts_on_topic_id"})
-> 0.0010s
-- add_index("posts", ["user_id"], {:name=>"index_posts_on_user_id"})
-> 0.0014s
-- create_table("questions", {:force=>:cascade})
-> 0.0010s
-- create_table("summaries", {:force=>:cascade})
-> 0.0010s
-- add_index("summaries", ["post_id"], {:name=>"index_summaries_on_post_id"})
-> 0.0010s
-- create_table("topics", {:force=>:cascade})
-> 0.0036s
-- create_table("users", {:force=>:cascade})
-> 0.0015s
-- add_index("users", ["commed_id"], {:name=>"index_users_on_commed_id"})
-> 0.0009s
-- add_index("users", ["comment_id"], {:name=>"index_users_on_comment_id"})
-> 0.0012s
-- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true})
-> 0.0015s
-- add_index("users", ["reset_password_token"], {:name=>"index_users_on_reset_password_token", :unique=>true})
-> 0.0017s
-- initialize_schema_migrations_table()
-> 0.0034s
rake aborted!
ActiveModel::MissingAttributeError: can't write unknown attribute `user_id`
/Users/jon/code/Bloccit/db/seeds.rb:45:in `block in <top (required)>'
/Users/jon/code/Bloccit/db/seeds.rb:44:in `times'
/Users/jon/code/Bloccit/db/seeds.rb:44:in `<top (required)>'
-e:1:in `<main>'
Tasks: TOP => db:setup => db:seed
(See full trace by running task with --trace)
Here is the full stack trace:
ActiveModel::MissingAttributeError: can't write unknown attribute `user_id`
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute.rb:138:in `with_value_from_database'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_set.rb:39:in `write_from_user'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_methods/write.rb:74:in `write_attribute_with_type_cast'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_methods/write.rb:56:in `write_attribute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_methods/dirty.rb:96:in `write_attribute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_methods.rb:373:in `[]='
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/associations/belongs_to_association.rb:83:in `replace_keys'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/associations/belongs_to_association.rb:14:in `replace'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/associations/singular_association.rb:17:in `writer'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/associations/builder/association.rb:123:in `user='
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:54:in `public_send'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:54:in `_assign_attribute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:35:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/attribute_assignment.rb:35:in `assign_attributes'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/core.rb:559:in `init_attributes'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/core.rb:281:in `initialize'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/inheritance.rb:61:in `new'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/inheritance.rb:61:in `new'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/persistence.rb:50:in `create!'
/Users/jon/code/Bloccit/db/seeds.rb:45:in `block in <top (required)>'
/Users/jon/code/Bloccit/db/seeds.rb:44:in `times'
/Users/jon/code/Bloccit/db/seeds.rb:44:in `<top (required)>'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:547:in `load_seed'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:250:in `load_seed'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:201:in `block in invoke_prerequisites'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `invoke_prerequisites'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:178:in `block in invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/railties/databases.rake:139:in `block (2 levels) in <top (required)>'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/Users/jon/code/Bloccit/bin/rake:8:in `<top (required)>'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/jon/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
-e:1:in `<main>'
Tasks: TOP => db:setup => db:seed
I am stumped here. I thought by deleting the old table and running the new generate commands + migrating everything would be in order. Apparently this is not the case.
What am I doing wrong here?
Thanks!
Rails: Dynamic from generation from the database
I've been scratching my brain (kinda painful, wouldn't advise it) trying to figure out a way to pull this off, but I haven't been able to come up with anything that really seems feasible.
The idea is this: I have a page that allows you to create an event. This event could be anything from a wedding to a marathon or fund raiser. Different events need to have a form specific to that event type, e.g. the wedding event needs the name of the bride, groom, address, receptions, etc.
What I'm trying to figure out is how to allow them to select an event type, and then go to localhost:3000/events/create(/:event_type) and have that view load in the correct form fields.
My original thought was to have event types stored in a database with each form stored as JSON, but this just seems more complicated than I'd think necessary.
Any ideas?
Here's routes.rb so far:
get 'my_events/', to: 'events#index', as: :events
get 'events/create', to: 'events#create', as: :new_event
match 'events/new', to: 'events#new', as: :post_new_event, via: :post
get 'event/:slug', to: 'events#show', as: :show_event
root 'static#index'
devise_for :users, :controllers => { :omniauth_callbacks => 'omniauth_callbacks' }
And the events controller:
class EventsController < ApplicationController
def index
@events = Event.all()
end
def create
@event = Event.new()
end
def show
@event = Event.find_by slug: params[:slug]
end
def delete
end
end
RSpec "retest broken tests from last time" flag
Is there any way to retest previously broken tests?
So, say, I run rspec and several tests in different files and directories fail. I fix something and now I have to manually specify all files and folders I want to retest or run tests for whole project again(It takes considerable amount of time for big projets).
What I was looking for is something like a flag
rspec --prev-failed-only
I realize that such flag would require considerable amount of additional actions from rspec, like storing results of previous tests and so on. But I think it would be super convenient to me.
Is there any such(or similar) tool/gem?
How to add extra param on best_in_place field update in ruby
I am using best_in_place gem for In-line edit for a field in active admin. Please look at my code below,
column "Badge ID", :number do |event|
best_in_place event, :number, :type => :input, :path => [:admin, event]
end
This is what the parameters sent to the controller action.
Parameters: {"event"=>{"number"=>"499"}, "authenticity_token"=>"xxxxxxxx", "id"=>"995"}
Now, I want to send additional parameter along with the number either inside or outside the event hash.
Anyone, Please help me resolve this.
How do I include a ruby gem's code into main rails project?
Let's say that I need to change the functionality of a certain ruby gem that I need in my rails project. I would like to place all the content of the ruby gem inside the main project.
Is this possible? Are there alternative methods?
Thank you
Kaminari gem not working with Leaderboard gem
I have been following this tutorial to get the leaderboard gem working and I've got all of the leaderboard gem aspect of it working, but I am struggling to get the Kaminari gem part of it working (the paginate gem).
At the moment in my controller I have this:
class LeaderboardController < ApplicationController
before_action :query_options
def show
@lb = Boards.default_leaderboard
@entries = entry_service.execute(query_options)
respond_to do |format|
format.html do
paginate
end
format.json do
render json: @entries
end
end
end
private
def query_options
@limit = [params.fetch(:limit, 10).to_i, 100].min
@page = params.fetch(:page, 1).to_i
{ page: @page, limit: @limit }
end
def paginate
pager = Kaminari.paginate_array(
@entries,
total_count: @lb.total_members)
@page_array = pager.page(@page).per(@limit)
end
And in the views I have:
= paginate @page_array
But for some reason this is not paginating the @entries...
Unresponsive Script Error in JS.erb File
Currently I have the Below code in a js.erb file in my ruby on rails project. What is happening is that the page is becoming unresponsive when this file is being used. Sometimes the @updates1 can have upwards of 100 records. is there a way to process the painting in the background and keep the UI responsive. With it the way it is the page becomes "locked up/unresponsive" for 10 sec to 1 minute. sometimes i get the warning of this page has become unresponsive.
My Code works just Takes A long time to process
Actual Code in the js.erb
var obj1 = {
"loads": <%= raw @updates1 %>
};
var count = 0;
var tab_keys = [];
$.each(obj1["loads"], function(k, v){
$.each(v, function(key, value) {
count++;
var addId = $('#' + key).dataTable().fnAddData(value);
var theNode = $('#' + key).dataTable().fnSettings().aoData[addId[0]];
theNode.nTr.setAttribute('id','row_' + value[0]);
$('#' + key).dataTable().fnAdjustColumnSizing();
tab_keys.push(key);
});
});
if (count > 0) {
var message = count + " More Loads!";
$.titleAlert(message, {
requireBlur:false,
stopOnFocus:false,
duration:8000,
interval:700
});
tab_keys = $.unique(tab_keys);
$.each(tab_keys, function(k, v){
var tab_key = v.replace(new RegExp("_load_results", "gi"), "");
var tab = 'a[href$="#tab_' + tab_key + '"]';
if ($(tab).parent().hasClass("ui-state-active") == true)
$(tab).css("font-weight","bold").parent().effect( 'highlight', {color: 'Blue'}, 7000);
else
$(tab).css("font-weight","bold").parent().css("background","#00D9D9").effect( 'highlight', {color: 'Blue'}, 7000);
});
if ( $('#prefs_can_be_screen_notified').val() == "1") {
playSound('/assets/'+$('#prefs_default_sound').val());
}
}
Results of what it is doing: BTW i cut the obj1 down in length for posting on here... It can sometimes be 100+ postings...
var obj1 = {
"loads": [{'25455_1431099504_load_results': ['13345499','2015-05-08 15:48:37 UTC','<abbr class=\"timeago\" title=\"2015-05-08 10:48:37\">1 minute</abbr>','Albuquerque, NM','Colorado Springs, CO','05/12','05/13','Full','Flatbed','','53']}, {'25455_1431099504_load_results': ['13345497','2015-05-08 15:48:37 UTC','<abbr class=\"timeago\" title=\"2015-05-08 10:48:37\">1 minute</abbr>','Gypsum, CO','Lincoln, NE','05/08','05/11','Full','Flatbed','','53']}]
};
var count = 0;
var tab_keys = [];
$.each(obj1["loads"], function(k, v){
$.each(v, function(key, value) {
count++;
var addId = $('#' + key).dataTable().fnAddData(value);
var theNode = $('#' + key).dataTable().fnSettings().aoData[addId[0]];
theNode.nTr.setAttribute('id','row_' + value[0]);
$('#' + key).dataTable().fnAdjustColumnSizing();
tab_keys.push(key);
});
});
if (count > 0) {
var message = count + " More Loads!";
$.titleAlert(message, {
requireBlur:false,
stopOnFocus:false,
duration:8000,
interval:700
});
tab_keys = $.unique(tab_keys);
$.each(tab_keys, function(k, v){
var tab_key = v.replace(new RegExp("_load_results", "gi"), "");
var tab = 'a[href$="#tab_' + tab_key + '"]';
if ($(tab).parent().hasClass("ui-state-active") == true)
$(tab).css("font-weight","bold").parent().effect( 'highlight', {color: 'Blue'}, 7000);
else
$(tab).css("font-weight","bold").parent().css("background","#00D9D9").effect( 'highlight', {color: 'Blue'}, 7000);
});
if ( $('#prefs_can_be_screen_notified').val() == "1") {
playSound('/assets/'+$('#prefs_default_sound').val());
}
}
Is there a way to get Android ID or UUID (Apple) from a rails app?
I am trying to track information for an app that will let me customize the experience for my users when they are not logged in. For this is would like to (if possibly) get my users Android ID or UUID (Apple). Is there any way to get this information once they are on mobile web?
Ruby on Rails - FTP error attempting to download file
I am using the following code to download a handful of .csv files from my FTP server:
require 'net/ftp'
ftp = Net::FTP.new
ftp.connect('myftpserver.com', '21')
ftp.login('mylogin', 'mypassword')
ftp.passive = true
files = ftp.list
puts files
ftp.gettextfile('cutandsold-us.csv', './lib/cutandsold-us.csv')
puts "#{Time.now} > Downloaded Cut and Sold report (US)."
ftp.gettextfile('cutandsold-canada.csv', './lib/cutandsold-canada.csv')
puts "#{Time.now} > Downloaded Cut and Sold report (CAN)."
ftp.gettextfile('stylemaster.csv', './lib/stylemaster.csv')
puts "#{Time.now} > Downloaded Style Master."
ftp.gettextfile('acct-bookings-large.csv', './lib/acct-bookings-large.csv')
puts "#{Time.now} > Downloaded Account Bookings report."
ftp.gettextfile('acctbookings-majors.csv', './lib/acctbookings-majors.csv')
puts "#{Time.now} > Downloaded Major Account Bookings report."
ftp.gettextfile('customerlist.csv', './lib/customerlist.csv')
puts "#{Time.now} > Downloaded Customer list."
ftp.close
All of the files download fine except for "customerlist.csv", despite this file being on the FTP server (I can download using FileZilla), and it shows up with the correct filename in the console when "puts files" occurs.
When the line to download "customerlist.csv" is reached, the following error is returned:
/Users/username/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/ftp.rb:341:in `voidresp': 150 0.085 seconds (measured here), 1.11 Mbytes per second (Net::FTPReplyError)
I suspect it is an issue with the file itself and not my code as the other files download without issue, but I am not sure because the file appears to be intact and I can download it with another FTP client.
How can I perform part of raw creating in ruby on rails?
for example:
My table is:
create table aaa {
a int not null auto_increment,
b int not null,
c varchar(255),
primary key (a,b)
}
Now, I want to insert a record
insert into aaa values (a,b,c)
((SELECT * from (select IFNULL(MAX(a)+1,1) as temp FROM aaa where b = 2) as P),
2,"what ever";
How can I achieve this?
The only solution I found is to make all of this become raw query in this page.
Can I write this something like that:
reault = Aaa.create({a: "(SELECT * from (select IFNULL(MAX(a)+1,1) as temp FROM aaa where b = 2) as P)", b: 2, c:"what ever"})
Only field a is used raw query and other part is wrote as usual?
rails: 4.2.1 DB gem is Mysql2
Jquery qtip "is not a function"
I'm trying to get qtip to work with rails FullCalendar, but haven't been able to get past the error "is not a function" when setting up a qtip. I'm just getting back in to Jquery/Rails and apparently this is typically a js file load issue. However, it seems like the js files are being loaded properly (in correct order and only once). Here are (some of) my js files:
<script src="/assets/jquery.self-d03a5518f45df77341bdbe6201ba3bfa547ebba8ed64f0ea56bfa5f96ea7c074.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/jquery_ujs.self-8e98a7a072a6cee1372d19fff9ff3e6aa1e39a37d89d6f06861637d061113ee7.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/jquery.qtip.self-c86ab2c0151d0748df498fc4603ec759f565e7966405872bad084728da15c92c.js?body=1" data-turbolinks-track="true"></script>
Looks to me like the js files are loading properly. I placed the calendar in application.js for now:
//= require jquery
//= require jquery_ujs
//= require jquery.qtip.js
$(document).ready(function(){
$("#calendar").fullCalendar({
eventSources : [{
url: 'url_to_get_data'
}],
eventLimit: true,
eventRender: function(event, element) {
element.qtip({
content: event.description
});
}
});
});
Anyone see anything glaringly wrong?
add info from rails_admin
i'm new in rails, and i'm building a rails app for a architect, so a client have many pictures. So i make my DB client and picture, and their link are in picture, the client_id.
https://www.youtube.com/watch?v=abcnfFS_DS8 This video help me a lot (see around 30min)
I don't want to create some forms or scaffolding system, i'd like to use the rails_admin gem to upload my picture(this is ok) and i propose to makes the relation and choose witch client i'd like to use, but this let my client_id at nil.
What should i do ?
This is my controller :
class RealisationController < ApplicationController
def real
@clients = Client.all
@pics = Picture.all
end
This is my models :
class Picture < ActiveRecord::Base
belongs_to :client
attr_accessible :client_name, :picture, :client, :image
has_attached_file :image,
:styles => { :medium => "300x300", :thumb => "100x100>" },
:path => ":rails_root/public/images/:id/:filename", #a changer pour mettre :id_client
:url => "/images/:id/:filename"
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
end
class Client < ActiveRecord::Base
# validates_presence_of :client_name
attr_accessible :client_name, :picture, :description
has_many :pictures, dependent: :destroy
accepts_nested_attributes_for :pictures, :allow_destroy => true
attr_accessible :pictures_attributes
end
This are my DB creation :
class CreatePictures < ActiveRecord::Migration
def change
create_table :pictures do |t|
t.integer :client_id
t.timestamps null: false
end
end
end
class AddAttachmentImageToPictures < ActiveRecord::Migration
def self.up
change_table :pictures do |t|
t.attachment :image
end
end
def self.down
remove_attachment :pictures, :image
end
end
class CreateClients < ActiveRecord::Migration
def change
create_table :clients do |t|
t.string :client_name
t.string :description
t.timestamps null: false
end
end
end
I feel it ! i'm really close to my goal ! But some help could be really helpful ..
Thanks for reading me, and sorry for my grammatical mistakes, i'm french ;)
Rails 4.2 Heroku app log disappeared
Well, I don't know where they are.
- Investigate
heroku logs.
Ok, I see there enough logs from my workers, they start well, but .. that's all!
After they started, I can't see any logs from them.
They put some logs at start up and report something to new relic, but after that they disappear. (ENV['NEW_RELIC_LOG'] = stdout)
- Investigate
heroku run rails c
Well, I see Rails.application.config and it's instance_values, they seem to be correct, "log_level = :debug" and "log_formatter = 'ActiveSupport::Logger::SimpleFormatter:0x007f06735586f8'"
Also I see this line: "log"=>#<Rails::Paths::Path:0x007f0673553f40 @paths=["log/staging.log"], @current="log", @root=#<Rails::Paths::Root:0x007f06735571b8 ...>
What's next?
I see many heroku router logs, but nothing else.
There is my config.
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.serve_static_files = true #ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end
Also I use Hobby Dev and Logentries on TryIt plan.
Maybe somebody can point to problem where they are disappear?
Rails has_many api interaction
I'm adding a new api interaction to a rails app. So, for this example, I have two models: a bag, and a thing. A bag can have many things. In my bag model, I have
has_many :things, :class_name => 'Api::Things'
and in my things model, I have
belongs_to :bag, :class => 'Api::Bag'
In my api (written in Go) I have
// Represents the json object that is returned to the end user when a request is made
type Thing struct {
Id int `db:"id" json:"id"`
Name string `db:"thing_name" json:"thing_name"`
ThingTypeId int `db:"thing_type_id" json:"thing_type_id"`
}
type ThingCollection struct {
Data []*Thing `json:"things"`
}
func (m *ThingCollection) List(bag_token string) error {
sql :=
`SELECT
ifnull(t.id,0) as id,
ifnull(t.thing_name,"") as thing_name,
ifnull(t.thing_type_id,0) as thing_type_id
FROM ` + dbNames.fakeDB + `.things t
JOIN ` + dbNames.fakeDB + `.bags b ON b.id = t.bag_id
WHERE b.token = '` + bag_token + `'`
return mysql.DB.Select(&m.Data, sql) --the mysql is defined in an import
}
I want my things to be populated when I make the api call to return a bag. This is not happening when I make that call in the bag controller. Do I need some kind of def self in the thing model? Am I missing something else?
Strategy to create multiple representations for the same class based on criteria using ROAR gem?
This is actually a best practices / usage question on hwo to use Roar & representable in Rails, as I didn't find any examples of that. Here are two scenarios. I use decorator pattern.
Scenario 1:
Let's say I have a Product class that has multiple attributes & association. By default when somebody makes a request to api.com/products/1 - I want to show everything I've got, but if somebody makes a request to another action like so http://ift.tt/1ImoJXo - I only want to show limited view that pertains to inventory ( to make it faster for inventory lookups) or if somebody makes a request to http://ift.tt/1DWj3eW - I want to return a matrix of related sub assemblies along with some relevant product details.
Questions for Scenario 1 :
- Do I create a specific representer for each case like ProductRepresenter, ProductInventoryDetailRepresenter, ProductAssemblyDetailRepresenter or do I use some kind of flow control in the ProductRepresenter?
- If I create multiple representers, for the same class, how can I use represents / respond_with pattern vs respond_to / render ?
- Can I override this on action level?
Scenario 2:
Let's say I have api.com/products/1 that both my internal application can call but that I also want to expose to my clients. However I don't want my clients to see some of the attributes, like inventory details or maybe just one or two attributes. Also depending on the level access of employee, I want to limit their view / representation.
Questions for Scenario 2 :
- Do I create a specific representer for each case like ProductRepresenter, ProductClientViewRepresenter or do I use some kind of flow control in the ProductRepresenter?
- If I create multiple representers, for the same class, how can I use represents / respond_with pattern vs respond_to / render ?
- Can I override this on an action level - based on the access type like: admin vs inventory_user vs shipping_user?
Any advice would be appriciated. (I'll cross-post this on github in Roar-Rails gem)
Vertically center a div in a Bootstrap Column
I've been trying yesterday to center vertically a "LinkedIn Connexion" div, with no success...
I've tried the "display: table" technique that I learned a few minutes ago but it still doesn't work... Can you help me find the issue ? I've learned Bootstrap last week and I've been having issues with all the "vertically centered" questions.``
Thanks in advance :)
.div[title="Connexion LinkedIn"] {
display: table;
width: 100%;
table-layout: fixed;
}
#linkedin-block {
display: table-cell;
vertical-align: middle;
Background-color: #eceded;
padding: 30px;
border-radius: 10px;
text-align: center;
}
<div class="col-lg-4 col-lg-offset-2" title="Connexion LinkedIn">
<div id="linkedin-block">
<h4>Connectez-vous via LinkedIn</h4>
<a href="<%= url_for connexion_linkedin_path %>"> <%= image_tag "linkedin.png", :style => "width:50px; margin:20px" %></a>
</div>
</div>
Best way to implement an interactive model of a house?
I am creating an interactive diagram of a house, which allows me to show current statistics of each room in the house, such as temperature or whether the lights are on/off. These will be automatically updated when changes are detected. What would be the best tool to use to create the model of the house? This would be within a Rails application.
Rails Backup: Generating Backup Model not running with dokku
Using Backup gem to do a DB backup, deployed the app with the gem installed to DigitalOcean and the next step is to run the generator using
dokku run oktob bundle exec backup generate:model --trigger oktob_db_backup --databases="postgresql" --storages="dropbox" --encryptors="openssl" --compressors="gzip" --notifiers="mail"
this should create the configuration files to setup the backup, but it returns nothing.
When I run the generator on my local machine, 2 files are generated as normal as but this time without using dokku run oktob as it's on a local machine.
Generated model file: '/Users/ahmadajmi/Backup/models/oktob_db_backup.rb'.
Generated configuration file: '/Users/ahmadajmi/Backup/config.rb'.
Thanks
Error when uploading video to heroku
I am using the paperclip and paperclip-av-transcoder in my rails app and I have gotten to the point where I can upload videos locally. But when I try it in heroku I get this error. Av::UnableToDetect (Unable to detect any supported library):
I may have to add something to make it work with s3 but I had it working with images earlier so everything should be setup for s3.
This is the code in my model
class Classvideo < ActiveRecord::Base
belongs_to :user
has_attached_file :video, :styles => {
:medium => {:geometry => "640x480", :format => 'flv'},
:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10 }
}, :processors => [:transcoder]
validates_attachment_content_type :video, :content_type => ["video/mp4", "video.mov", "video/mpeg","video/mpeg4", "image/jpg", "image/jpeg"]
end
S3 direct upload remove video
I'm using "s3 direct upload" gem, but I want to let user to delete the file. 1) Emby the calumn from the database 2) Delete file from AWS <%= s3_uploader_form callback_url: polymorphic_url([@academy, :dashboard, @course, @lesson], {only_path: false}),callback_method: "PUT", callback_param: "lesson[#{video_format}]", class: "s3-uploader" do %> <%= file_field_tag :file, multiple: true %> <% end %>
Best size: 800x450px
<script id="template-upload" type="text/x-tmpl">
<div id="file-{%=o.unique_id%}" class="upload">
{%=o.name%}
<div class="progress"><div class="bar" style="width: 0%"></div></div>
</div>
</script>
Let user update their password without current password in devise
I am on rails 4.2.1 and devise 3.4.1. I basically want 2 things at same time:
Allow users to edit their password
and
Allow users to edit their account without providing a password
I managed to have them working separately. But solution 1 for the first problem seems to be, I'm afraid, incompatible with the only official solution for the second problem because, for the latter, I need to override the registration controller.
Hence I tried to do the solution 1 job in the registration controller rather than the application one:
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :configure_account_update_params, only: [:update]
protected
def configure_account_update_params
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:name, :password, :password_confirmation, :current_password) }
end
def update_resource(resource, params)
resource.update_without_password(params)
end
end
This way only added attribute like name get updated while password is completely filtered out. I am not sure I should start an heavy customization as in solutions 2 and 3 for such a simple aim.. Am I missing anything?
Starting a Heroku worker dyno when someone is on site
In order get more bang for my buck, I am using the workless gem to dynamically start and stop my worker dyno when a job is created. I find that starting the dyno takes a bit too long to start up. Is there any way to have the dyno spin up as soon as someone gets on my homepage?
Rake assets:clobber and precompile causes git merge conflicts
Using Rails 4.0.3. I am going to push my application updates to Heroku. Because I was working with assets, I wanted to clean them up and create a fresh copy, so I did a clobber and precompile. This action alone seems to have created a git merge conflict. Or, am I missing something? I've resolved simple conflicts in the past, but this one is new to me. Can you please tell me how to resolve this?
The process follows:
D:\BitNami\rubystack-2.0.0-11\projects\myapp>git status
On branch version-1.10
nothing to commit, working directory clean
D:\BitNami\rubystack-2.0.0-11\projects\myapp>rake assets:clobber
I, [2015-05-08T01:01:19.335136 #2408] INFO -- : Removed D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
rm -rf D:/BitNami/rubystack-2.0.0-11/projects/myapp/tmp/cache/assets
D:\BitNami\rubystack-2.0.0-11\projects\myapp>rake assets:clobber RAILS_ENV=production
I, [2015-05-08T01:01:53.080552 #19172] INFO -- : Removed D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
rm -rf D:/BitNami/rubystack-2.0.0-11/projects/myapp/tmp/cache/assets
D:\BitNami\rubystack-2.0.0-11\projects\myapp>rake assets:precompile RAILS_ENV=production
I, [2015-05-08T01:02:33.624102 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/DeleteRed-72974c2d1f1b09a69eaad352188195f1.png
I, [2015-05-08T01:02:33.631107 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/Icons-mini-arrow_down-de80f42604ea54e80253147693682b62.gif
I, [2015-05-08T01:02:33.637105 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/Icons-mini-arrow_up-e617865776fb86a10537559fc2754516.gif
I, [2015-05-08T01:02:33.685105 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/car-549da5fcc265386244e55bcc780c7b28.ico
I, [2015-05-08T01:02:33.710107 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/my_app_redesign_color01-cd3e7ed32fd0c6d156a8c5c9d2ff295a.jpg
I, [2015-05-08T01:02:33.731126 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/my_app_redesign_color02-07e39a32da11981bf742fb8202b096ac.jpg
I, [2015-05-08T01:02:33.782144 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/rails-388e5a3b3ae0e085310a99f179f8291e.png
I, [2015-05-08T01:02:33.796116 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/small_x1-3c5f818780cc27bfa11f1e8e6c087f8d.png
I, [2015-05-08T01:02:33.813116 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/small_x2-7fae117327e56b60d98872466ab71b3b.png
I, [2015-05-08T01:02:33.820116 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/sort_asc-c3327239e8dc0ce9b9288525c3d30d26.png
I, [2015-05-08T01:02:33.827116 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/sort_both-67d0bbd65de0d3462b31c7ee0fa29bc5.png
I, [2015-05-08T01:02:33.835122 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/sort_desc-5c901fc353f19d7583b77307851c654d.png
I, [2015-05-08T01:02:42.015594 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/application-1798a300bc1f81021835b0756391310e.js
I, [2015-05-08T01:02:59.105732 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/application-3aaccdca55fee944386353ada7eea718.css
I, [2015-05-08T01:02:59.134736 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/bootstrap/glyphicons-halflings-regular-2858f48657aa30e02d2095342471ba00.eot
I, [2015-05-08T01:02:59.141736 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/bootstrap/glyphicons-halflings-regular-648858aa889a3d23a6e3414ba8a0a02d.svg
I, [2015-05-08T01:02:59.149733 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/bootstrap/glyphicons-halflings-regular-2858f48657aa30e02d2095342471ba00.ttf
I, [2015-05-08T01:02:59.157749 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/bootstrap/glyphicons-halflings-regular-2858f48657aa30e02d2095342471ba00.woff
I, [2015-05-08T01:02:59.172739 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/jquery-ui/ui-bg_flat_0_aaaaaa_40x100-1fa83da988c496f3b6b4a3132cd4cc63.png
I, [2015-05-08T01:02:59.186741 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/jquery-ui/ui-bg_flat_75_ffffff_40x100-1a84f396ed6cc5bdc44ae13e12c9413b.png
I, [2015-05-08T01:02:59.203741 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/jquery-ui/ui-bg_glass_55_fbf9ee_1x400-46a7e08af592714fc92f4d87aa2fca36.png
I, [2015-05-08T01:02:59.218742 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/jquery-ui/ui-bg_glass_65_ffffff_1x400-5f6e0ce2d23eab39b1b83abf05f99801.png
I, [2015-05-08T01:02:59.234744 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/jquery-ui/ui-bg_glass_75_dadada_1x400-76719558bfb6b9566c2b342b516d1756.png
I, [2015-05-08T01:02:59.249744 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/jquery-ui/ui-bg_glass_75_e6e6e6_1x400-cdb62f296e7f3c6b81584cc81ff76eeb.png
I, [2015-05-08T01:02:59.264746 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/jquery-ui/ui-bg_glass_95_fef1ec_1x400-b22e32502f5f6c863f05ff9810edaa7e.png
I, [2015-05-08T01:02:59.281738 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/jquery-ui/ui-bg_highlight-soft_75_cccccc_1x100-1cb58b68cf84331f41762764b70fa8ef.png
I, [2015-05-08T01:02:59.324748 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/jquery-ui/ui-icons_222222_256x240-ea6f8ed84f165dd1c63d808ec96acac9.png
I, [2015-05-08T01:02:59.348748 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/jquery-ui/ui-icons_2e83ff_256x240-1995ab092f581d8377229fadb3fd3e80.png
I, [2015-05-08T01:02:59.393748 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/jquery-ui/ui-icons_454545_256x240-ca04cac8ea32b6f64180b393767edf7a.png
I, [2015-05-08T01:02:59.409749 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/jquery-ui/ui-icons_888888_256x240-bfea01de5d1c764771cebbf65d29e0ae.png
I, [2015-05-08T01:02:59.425753 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/jquery-ui/ui-icons_cd0a0a_256x240-16a4f218fe0bc71ff70cd8ed1771d7e0.png
I, [2015-05-08T01:02:59.485757 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/back_disabled-2e043033788cbcf14ae236ba2eeadee8.png
I, [2015-05-08T01:02:59.514757 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/back_enabled-ffc4b78cfa00d243d5519e50e27b5a25.png
I, [2015-05-08T01:02:59.576761 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/back_enabled_hover-a8b3cd1ae492dfbfe5e7af736750d72f.png
I, [2015-05-08T01:02:59.610762 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/background-3830dcf30531da31ae142f6ffa6e8457.png
I, [2015-05-08T01:02:59.655766 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/button-823be07e05e95f1b91dd7eb427c5c912.png
I, [2015-05-08T01:02:59.681770 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/collection-9e2788624a471583e80fc45b1f127a37.png
I, [2015-05-08T01:02:59.713771 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/collection_hover-d07133b5bf48cff29661eb6d850a7e85.png
I, [2015-05-08T01:02:59.735762 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/copy-eb7e698ba0c415a51347efe353abe1ce.png
I, [2015-05-08T01:02:59.762781 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/copy_hover-31e4694d3ee212559ae8cb09e1413a30.png
I, [2015-05-08T01:02:59.790799 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/csv-a826cb6f02a8755a6eb9f2b8051aff78.png
I, [2015-05-08T01:02:59.817777 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/csv_hover-49279f2880fafc7a95feb0b5b9c8fc24.png
I, [2015-05-08T01:02:59.843778 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/filler-e3f09fe70da389e038490135d095fb3d.png
I, [2015-05-08T01:02:59.863779 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/insert-9b514534dc3e295db24f4eeaeb0dba6f.png
I, [2015-05-08T01:02:59.889773 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/loading-background-0c5044dfffc24a4b4d3d4c49aab3afdb.png
I, [2015-05-08T01:02:59.914796 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/pdf-e40d4977e19d068e152584c00be17f62.png
I, [2015-05-08T01:02:59.938790 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/pdf_hover-34e9686212f592f24ea473c6c2d15e3e.png
I, [2015-05-08T01:02:59.968792 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/print-5bb36a9a8dd59c287b3123635b4a5fde.png
I, [2015-05-08T01:03:00.001779 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/print_hover-e389208bc53c2bd350e88b5917bd2c5f.png
I, [2015-05-08T01:03:00.041790 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/xls-4fd2177e8c25751a1515eb24754c253f.png
I, [2015-05-08T01:03:00.065796 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/xls_hover-4acc4c8c272ec8b8aab78d368a52318b.png
I, [2015-05-08T01:03:00.097794 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/favicon-341436b780b92a3b318b49bab25a873e.ico
I, [2015-05-08T01:03:00.122795 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/forward_disabled-038e00252a33b149865def6eb7c070eb.png
I, [2015-05-08T01:03:00.143806 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/forward_enabled-8dfc268d3c294b7f4f278fba197191a2.png
I, [2015-05-08T01:03:00.171798 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/forward_enabled_hover-bda11f9300cc8a0c4f5241a8f0413074.png
I, [2015-05-08T01:03:00.195801 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/foundation/sort_asc-e9ea7d12b915dd5d2fc3c183c2281ff5.png
I, [2015-05-08T01:03:00.220802 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/foundation/sort_asc_disabled-9ae5f25540cc831074ef8f4d089b8fe0.png
I, [2015-05-08T01:03:00.258800 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/foundation/sort_both-3950cff0b82a0a66e490e77ebaf0b096.png
I, [2015-05-08T01:03:00.297798 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/foundation/sort_desc-3570c455229f720ad6721dd5ad40cae6.png
I, [2015-05-08T01:03:00.330803 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/foundation/sort_desc_disabled-10a749a2c2bfb14557136b4f665f80bb.png
I, [2015-05-08T01:03:00.347807 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/minus-d2ac7be6d76c50e9cb233db5597832dc.png
I, [2015-05-08T01:03:00.364808 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/plus-a6f41f2a37b65403175819cd739cdd98.png
I, [2015-05-08T01:03:00.388812 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/sort_asc-e9ea7d12b915dd5d2fc3c183c2281ff5.png
I, [2015-05-08T01:03:00.405813 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/sort_asc_disabled-0784e0dbe2aada0c1c7af14db00f0f5c.png
I, [2015-05-08T01:03:00.425813 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/sort_both-3950cff0b82a0a66e490e77ebaf0b096.png
I, [2015-05-08T01:03:00.448813 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/sort_desc-3570c455229f720ad6721dd5ad40cae6.png
I, [2015-05-08T01:03:00.473816 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/sort_desc_disabled-10a749a2c2bfb14557136b4f665f80bb.png
I, [2015-05-08T01:03:00.503813 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/as3/ZeroClipboard-81de8a64fbae2fa83c5512d540b48e21.as
I, [2015-05-08T01:03:00.521820 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/as3/ZeroClipboardPdf-ba907045edd5a364a919f76731ffe9f5.as
I, [2015-05-08T01:03:00.554817 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/as3/lib/AlivePDF-537866e1cd4473a99eba0f8a4097f19d.swc
I, [2015-05-08T01:03:00.587819 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/swf/copy_csv_xls-699fcec8370ef13b4606dd9f47ba0218.swf
I, [2015-05-08T01:03:00.619815 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/dataTables/extras/swf/copy_csv_xls_pdf-666e4aef3ce6c8595f6a97b4c05b619e.swf
I, [2015-05-08T01:03:00.652826 #16836] INFO -- : Writing D:/BitNami/rubystack-2.0.0-11/projects/myapp/public/assets
/bootstrap/glyphicons-halflings-regular-5840366f483f32e8e39f6d867b9dccd3.woff2
D:\BitNami\rubystack-2.0.0-11\projects\myapp>git add --all
warning: LF will be replaced by CRLF in public/assets/application-1798a300bc1f81021835b0756391310e.js.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in public/assets/application-3aaccdca55fee944386353ada7eea718.css.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in public/assets/dataTables/extras/as3/ZeroClipboard-81de8a64fbae2fa83c5512d540b48e
21.as.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in public/assets/dataTables/extras/as3/ZeroClipboardPdf-ba907045edd5a364a919f76731f
fe9f5.as.
The file will have its original line endings in your working directory.
D:\BitNami\rubystack-2.0.0-11\projects\myapp>git commit -m "clobber and precompile"
[version-1.10 c1bf1bb] clobber and precompile
5 files changed, 1 insertion(+), 569 deletions(-)
rename public/assets/{manifest-f6ed403257c515fde435a4efeec74088.json => manifest-f45e404b1fde7bd606849e1b56691dbe.json}
(99%)
delete mode 100644 public/assets/source_maps/bundler/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.coffee
delete mode 100644 public/assets/source_maps/bundler/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.map
D:\BitNami\rubystack-2.0.0-11\projects\myapp>git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
D:\BitNami\rubystack-2.0.0-11\projects\myapp>git merge version-1.10
warning: Cannot merge binary files: public/assets/application-65733beab0cc71ee0dc6ab288a7074c1.js.gz (HEAD:public/assets
/application-65733beab0cc71ee0dc6ab288a7074c1.js.gz vs. version-1.10:public/assets/application-1798a300bc1f81021835b0756
391310e.js.gz)
Removing public/assets/source_maps/bundler/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.map
Removing public/assets/source_maps/bundler/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.coffee
CONFLICT (rename/rename): Rename "public/assets/manifest-f6ed403257c515fde435a4efeec74088.json"->"public/assets/manifest
-d86323e8d0d88233e3438587840eff30.json" in branch "HEAD" rename "public/assets/manifest-f6ed403257c515fde435a4efeec74088
.json"->"public/assets/manifest-f45e404b1fde7bd606849e1b56691dbe.json" in "version-1.10"
Auto-merging public/assets/application-65733beab0cc71ee0dc6ab288a7074c1.js.gz
CONFLICT (content): Merge conflict in public/assets/application-65733beab0cc71ee0dc6ab288a7074c1.js.gz
Automatic merge failed; fix conflicts and then commit the result.
Object with more than one Model (Rails)
BACKGROUND: I'm thinking conceptually about how to reference a single object that can belong to more than one model. For instance, if I have a School and Employer model - a User could theoretically have attended and be employed at the same School. Ideally both relationships to point to the same object.
QUESTION: How would I model that in a postgresql-based Rails app?
UPDATE In this case, I'd need a user to be able to have both one or more Schools and one or more Employers.
Debug integration test
When an integration test fails, even though the thing it's testing works with manual testing, it can be hard to work out what went wrong.
Here for example (fails):
test "posts a job with valid information" do
get new_job_path
assert_difference 'Job.count', 1 do
post_via_redirect jobs_path,
job: { title: "Great job",
description: "Please apply to our great job!",
company: "Fast company",
contact_info: "Email a cv to user@fastcompany.com",
categroy_id: "1" },
employer: { email: "user@fastcompany.com" },
location: { address_1: "21 Corsham Street",
address_2: "Islington",
postcode: "N1 6DD" }
end
assert_template 'jobs/show'
assert_not flash.empty?
end
This same data entered into the website doesn't fail.
Infact, you can output the response by changing the assert_difference line to:
assert_difference 'Job.count', 1, @response.body do
Here, I've use the "failure message" field of the test to print the body. Unfortunately, the response is looking very weird - it looks like it just refreshed the page. How can I get in and see what's wrong?
For reference, here's the controller and view being tested:
I'm using minitest.
Controller:
def create
@employer = Employer.find_or_create_by(employer_params)
@location = @employer.locations.build(location_params)
@job = @employer.jobs.build(job_params)
unless @location.save
@job.errors.delete(:employer_id)
@location.errors.delete(:lat)
@location.errors.delete(:lng)
render 'new' and return
end
@job.location = @location
if @job.save
flash[:success] = "Job posted successfully!"
redirect_to @job
else
@job.errors.delete(:employer_id)
@location.errors.delete(:lat)
@location.errors.delete(:lng)
render 'new'
end
end
View:
<% provide(:title, 'Post a Job') %>
<h1>Post a Job</h1>
<div class="row">
<div class="col-sm-4 col-sm-push-4">
<%= form_for(@job) do |j| %>
<%= render 'shared/error_messages' %>
<%= j.label :category %>
<%= j.collection_select :category_id, Category.all, :id, :name_titleize, { prompt: "Select vehicle" }, { class: 'form-control' } %>
<%= j.label :title %>
<%= j.text_field :title, class: 'form-control' %>
<%= j.label :description %>
<%= j.text_area :description, class: 'form-control' %>
<%= j.label :contact_info %>
<%= j.text_area :contact_info, class: 'form-control' %>
<%= j.label :company %>
<%= j.text_field :company, class: 'form-control' %>
<%= fields_for @employer do |e| %>
<%= e.label :email %>
<%= e.email_field :email, class: 'form-control' %>
<% end %>
<%= fields_for :location, @location do |l| %>
<%= l.label :address_1 %>
<%= l.text_field :address_1, class: 'form-control' %>
<%= l.label :address_2 %>
<%= l.text_field :address_2, class: 'form-control' %>
<%= l.label :postcode %>
<%= l.text_field :postcode, class: 'form-control' %>
<% end %>
<%= j.submit "Post my job", class: "btn btn-primary" %>
<% end %>
</div>
</div>
Can't run my rspec test with jRuby and Rails 4.1.4
I have a Rails application (4.1.4) running with jRuby 1.7.15 (1.9.3p392) 2014-09-03 82b5cc3 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_67-b01.
You can see my Gemfile at: http://ift.tt/1FTGsn5.
My Gemfile.lock: http://ift.tt/1GTsvln.
As you can see I'm using rspec (2.14.1) and rspec-rails (2.14.2).
I have a user_spec.rb file something like this:
require 'spec_helper'
describe User do
include_context "stubbed organization"
subject { build_stubbed(:super_admin, organization: organization) }
let(:notification_queue) { build_stubbed(:notification_queue) }
before(:each) do
allow(NotificationQueue).to receive(:find_each)
end
it "has name assigned" do
user = build(:member, first_name: 'John', last_name: 'Smiths')
expect(user.first_name).to eq('John')
expect(user.last_name).to eq('Smiths')
end
it "has a first name" do
subject.first_name = nil
expect(subject).not_to be_valid
end
it "has a last name" do
subject.last_name = nil
expect(subject).not_to be_valid
end
end
and once I run the test I get the following results:
⇒ rspec spec/models/user_spec.rb
/Users/info/.rvm/gems/jruby-1.7.15@j-platform/gems/simplecov-0.8.2/lib/simplecov.rb:31 warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
[rspec-sidekiq] WARNING! Sidekiq will *NOT* process jobs in this environment. See http://ift.tt/1vqGeMo
3/3: ****************************************_,------,
0/3: ****************************************_| /\_/\
0/3: ****************************************~|_( x .x)
3/3: **************************************** "" ""
Failures:
1) User has a first name
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `has_key?' for nil:NilClass
# ./app/models/client.rb:125:in `initialize_apps_data'
# ./spec/shared/stubbed_organization.rb:3:in `client'
# ./spec/shared/stubbed_organization.rb:15:in `(root)'
2) User has a last name
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `has_key?' for nil:NilClass
# ./app/models/client.rb:125:in `initialize_apps_data'
# ./spec/shared/stubbed_organization.rb:3:in `client'
# ./spec/shared/stubbed_organization.rb:15:in `(root)'
3) User has name assigned
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `has_key?' for nil:NilClass
# ./app/models/client.rb:125:in `initialize_apps_data'
# ./spec/shared/stubbed_organization.rb:3:in `client'
# ./spec/shared/stubbed_organization.rb:15:in `(root)'
My rspec installed locally:
⇒ gem list | grep rspec
guard-rspec (4.2.9)
rspec (3.2.0, 2.14.1, 2.13.0)
rspec-core (3.2.3, 2.14.8, 2.13.1)
rspec-expectations (3.2.1, 2.14.5, 2.13.0)
rspec-mocks (3.2.1, 2.14.6, 2.13.1)
rspec-rails (3.2.1, 2.14.2, 2.13.0, 2.0.0.beta.18)
rspec-sidekiq (1.0.0)
rspec-support (3.2.2)
spring-commands-rspec (1.0.2)
If I move to use ruby-2.0.0-p353 and bundle install the gems and then trying to run the same test, I get the followings:
⇒ bundle exec rspec spec/models/user_spec.rb
/Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require': dlopen(/Users/info/.rvm/gems/ruby-2.0.0-p353/gems/http_parser.rb-0.6.0/lib/ruby_http_parser.bundle, 9): Library not loaded: @executable_path/../lib/libruby.1.9.1.dylib (LoadError)
Referenced from: /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/http_parser.rb-0.6.0/lib/ruby_http_parser.bundle
Reason: image not found - /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/http_parser.rb-0.6.0/lib/ruby_http_parser.bundle
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/http_parser.rb-0.6.0/lib/http_parser.rb:2:in `<top (required)>'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/http_parser.rb-0.6.0/lib/http/parser.rb:1:in `<top (required)>'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/twitter-5.9.0/lib/twitter/streaming/connection.rb:1:in `<top (required)>'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/twitter-5.9.0/lib/twitter/streaming/client.rb:4:in `<top (required)>'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/twitter-5.9.0/lib/twitter.rb:26:in `<top (required)>'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.4/lib/bundler/runtime.rb:72:in `each'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.4/lib/bundler/runtime.rb:72:in `block in require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.4/lib/bundler/runtime.rb:61:in `each'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.4/lib/bundler/runtime.rb:61:in `require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/bundler-1.7.4/lib/bundler.rb:133:in `require'
from /Users/info/code/plumtales/j-platform/config/application.rb:9:in `<top (required)>'
from /Users/info/code/plumtales/j-platform/config/environment.rb:2:in `require'
from /Users/info/code/plumtales/j-platform/config/environment.rb:2:in `<top (required)>'
from /Users/info/code/plumtales/j-platform/spec/spec_helper.rb:11:in `require'
from /Users/info/code/plumtales/j-platform/spec/spec_helper.rb:11:in `block in <top (required)>'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/spork-1.0.0rc4/lib/spork.rb:24:in `prefork'
from /Users/info/code/plumtales/j-platform/spec/spec_helper.rb:7:in `<top (required)>'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:867:in `require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:867:in `block in setup_load_path_and_require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:867:in `each'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:867:in `setup_load_path_and_require'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-2.14.8/lib/rspec/core/configuration_options.rb:25:in `configure'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:21:in `run'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
from /Users/info/.rvm/gems/ruby-2.0.0-p353/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'
Please note that the gems installed locally:
⇒ gem list | grep rspec
guard-rspec (4.3.1, 4.2.9, 4.2.8, 4.2.0, 3.1.0)
mongoid-rspec (1.10.0)
mutant-rspec (0.5.10)
opal-rspec (0.3.0.beta3)
rspec (3.0.0, 2.99.0, 2.14.1, 2.12.0)
rspec-collection_matchers (1.0.0)
rspec-core (3.1.7, 3.0.4, 3.0.3, 2.99.2, 2.14.8, 2.14.7, 2.14.6, 2.14.5, 2.14.4, 2.12.2)
rspec-expectations (3.1.2, 3.0.4, 3.0.3, 2.99.2, 2.14.5, 2.14.4, 2.14.3, 2.14.0, 2.12.1)
rspec-given (3.1.1)
rspec-html-matchers (0.5.0)
rspec-instafail (0.2.4)
rspec-mocks (3.0.4, 3.0.3, 2.99.2, 2.14.6, 2.14.4, 2.14.3, 2.14.1, 2.12.1)
rspec-rails (3.0.2, 2.99.0, 2.14.2, 2.14.1, 2.14.0, 2.0.0.beta.18)
rspec-sidekiq (1.0.0)
rspec-spies (2.1.4)
rspec-support (3.1.2, 3.0.4, 3.0.3)
rspec_junit_formatter (0.2.0, 0.1.6)
spring-commands-rspec (1.0.2)
Any help would be appreciated.
Generating dynamic child rows in partial
I have implemented a nice nested attribute form using the excellent nested attributes Railscast as a guide. As a result, the user can click an icon to dynamically add "child" rows to my form. When I try to make the original rows work the same way, I find that I cannot pass the parent object to the partial as a local. Is there a better way to do this?
Pertinent code snippets:
My view (builds the children and creates link to add more rows):
= sheet.fields_for :slots do |builder|
= render 'slots/edit_fields', sheet:sheet, f: builder, slots: :slots
= link_to_add_fields image_tag("plus.jpg", size:"18x18", alt:"Plus"), sheet, :slots, "slots/edit"
... the above works except for sheet: sheet - this is Nil in my partial.
My partial:
.row.signup
.col-md-1
%span.plus-icon
= link_to_add_fields image_tag("plus.jpg", size:"18x18", alt:"Plus"), sheet, slots, "slots/edit"
%span.minus-icon
= image_tag "minus.jpg", size:"18x18", alt:"Minus"
.col-md-2= f.text_field :label
.col-md-2= f.text_field :name
.col-md-2= f.text_field :email
.col-md-2= f.text_field :phone
.col-md-2= f.text_field :comments
My helper:
module ApplicationHelper
def link_to_add_fields(name, f, association, partial)
new_object = f.object.send(association).klass.new
id = new_object.object_id
fields = f.fields_for(association, new_object, child_index: id) do |builder|
render(partial.to_s.singularize + "_fields", f: builder, name: name)
end
link_to(name, '#', class: "add_fields", data: {id: id, fields: fields.gsub("\n", "")})
end
end
... since I cannot pass sheet to my partial, I can't get f defined here and am not able to generate new_object.
The error I get is undefined local variable or method 'sheet' for #<#<Class:0x007f2f19080e18>:0x007f2f04442f70> on the link_to_add_fields call in the partial and when I debug, the value is Nil as I mentioned.
Thanks in advance for your help and suggestions. I am about to give up and implement this with Ajax but am hoping I am close to a more elegant solution.