[Rails] Re: Prime user table for the first user

2017-07-13 Thread Matt Jones


On Tuesday, 11 July 2017 09:33:05 UTC-4, Ralph Shnelvar wrote:
>
> Let's say I expect to have a billion users in my Postgres users table.
>
> I want to make sure the first user gets to set it's role attribute to enum 
> :admin as the default when the record is created and all other users are 
> enum  :user.
>
> Of course a billion users is ridiculous.  I'm just trying to understand 
> what the, uh, best way to see if a Postgres table is empty without actually 
> having to load it.
>

I suspect `User.exists?` is going to be the lightest possible option. 
`User.count == 0` will also work, but I know there are some DBs where that 
operation can be expensive on large tables.

This is still going to do a query every time it checks, so if that's too 
much load you could cache the result:

class User < ActiveRecord::Base
  def self.any_users?
@any_users ||= exists?
  end
end

Then your role-defaulting code can check `self.class.any_users?`, which 
will only run one query (per server) that returns true.

NOTE NOTE NOTE: the above is not 100% thread-safe. It assumes that there is 
exactly one user sending requests trying to be the first. If you're worried 
about somebody racing to sign up for that first account, you'll want to 
come up with a more secure approach.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/34b5bba4-3914-4106-9f05-0e61053250c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: One database and several users with different access rights

2017-07-12 Thread Matt Jones


On Tuesday, 11 July 2017 23:39:13 UTC-4, Ralph Shnelvar wrote:
>
> I have a database with a large table.
>
> I have several users each of whom should have read-only rights to the 
> large table but has read/wrtie rights to their own table(s) but not to each 
> others table(s).
>
> Adding to the complication, I want to give each RoR user the ability to 
> write their own SQL statements against the large table as well as their own 
> table(s).  I have successfully implemented being able to have them enter 
> sql statements and create results they can view and/or download.  Doing 
> that is not my question.
>
> I want to make sure each of my "readonly" users can't modify any tables 
> they are not authorized to see and/or change.
>
> So,I guess, I want to change Postgres roles within Rails.  Any guidance 
> would, of course, be appreciated.
>

I've never used it, but something like "SET SESSION AUTHORIZATION"  looks 
like it would do what you want, mostly:

https://www.postgresql.org/docs/current/static/sql-set-session-authorization.html

You'd set up a "superuser" in config/database.yml and then change to the 
lower-privileged specific user per-request.

Some potential problems:

* the lower-privileged users *must* not have sufficient permissions to call 
"SET SESSION AUTHORIZATION" themselves or the security is an illusion

* you'll want to make 100% certain that connections get a "RESET SESSION 
AUTHORIZATION", or a selected user's authorization will leak into the next 
request (and fail, see the previous point)

* you'll need to somehow sanitize the incoming SQL to remove queries like 
"RESET SESSION AUTHORIZATION; DROP TABLE all_the_things" or the security is 
an illusion

I noticed you mentioned "their own tables" above; if you're already 
committed to solutions where adding users is complex, you might want to 
think about separating things further. You could use a tool like pglogical:

https://www.2ndquadrant.com/en/resources/pglogical/

To replicate only the large table to per-user Postgres DBs. Definitely NOT 
an appropriate solution for multi-tenancy with lots of users, but neither 
is table-per-user.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/af2f5066-1ac6-4971-98e8-2acbfeb0be31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Custom UUID generator

2017-07-10 Thread Matt Hickman
That statement you pasted defines it, it's stored as a function in 
postgres. See https://www.postgresql.org/docs/9.5/static/xfunc-sql.html 
for docs on how this works in postgres.



John Pearson <mailto:johnpearson...@gmail.com>
July 10, 2017 at 2:36 PMvia Postbox 
<https://www.postbox-inc.com/?utm_source=email_medium=sumlink_campaign=reach>

My question, if this is my migration:

*migration.rb*
def change

connection.execute <<-SQL

CREATE OR REPLACE FUNCTION john_uuid_generator() RETURNS uuid

AS $$ SELECT * FROM #{uuid_function} $$

LANGUAGE SQL VOLATILE;

SQL

end


Where do I define john_uuid_generator()?

Thanks!




--
You received this message because you are subscribed to the Google 
Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to rubyonrails-talk+unsubscr...@googlegroups.com 
<mailto:rubyonrails-talk+unsubscr...@googlegroups.com>.
To post to this group, send email to rubyonrails-talk@googlegroups.com 
<mailto:rubyonrails-talk@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAKNtY_x1qm_VXqcUdMXQ8pytHQF2tFuLAmgnv%2Bvf-8uZGXBMqw%40mail.gmail.com 
<https://groups.google.com/d/msgid/rubyonrails-talk/CAKNtY_x1qm_VXqcUdMXQ8pytHQF2tFuLAmgnv%2Bvf-8uZGXBMqw%40mail.gmail.com?utm_medium=email_source=footer>.

For more options, visit https://groups.google.com/d/optout.



--
Matt

--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/5963FD32.8070208%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Custom UUID generator

2017-07-10 Thread Matt Hickman
uuid_function is defined - 
https://github.com/rails/rails/blob/650ea5e5cf50d8a7242499463cf1762922d330a8/activerecord/test/cases/adapters/postgresql/uuid_test.rb#L14 
- it just switches on if postgres supports gen_random_uuid() otherwise 
it uses uuid_generate_v4()


gen_random_uuid() is part of the pgcrypto module - 
https://www.postgresql.org/docs/9.5/static/pgcrypto.html


uuid_generate_v4() is part of the uuid-ossp module - 
https://www.postgresql.org/docs/9.5/static/uuid-ossp.html

johnpearson...@gmail.com <mailto:johnpearson...@gmail.com>
July 10, 2017 at 12:39 PMvia Postbox 
<https://www.postbox-inc.com/?utm_source=email_medium=sumlink_campaign=reach>
That's what I thought but I wasn't sure where to place the 
uuid_function 
<https://github.com/rails/rails/blob/650ea5e5cf50d8a7242499463cf1762922d330a8/activerecord/test/cases/adapters/postgresql/uuid_test.rb#L13> that 
the migration refers to. So that go in a helper file or part of the 
migration?


On Monday, July 10, 2017 at 4:38:06 AM UTC-7, Matt Hickman wrote:
--
You received this message because you are subscribed to the Google 
Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to rubyonrails-talk+unsubscr...@googlegroups.com 
<mailto:rubyonrails-talk+unsubscr...@googlegroups.com>.
To post to this group, send email to rubyonrails-talk@googlegroups.com 
<mailto:rubyonrails-talk@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/ea4c0dbb-317d-428a-9534-80ca70b1e2f3%40googlegroups.com 
<https://groups.google.com/d/msgid/rubyonrails-talk/ea4c0dbb-317d-428a-9534-80ca70b1e2f3%40googlegroups.com?utm_medium=email_source=footer>.

For more options, visit https://groups.google.com/d/optout.



--
Matt

--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/5963ED2A.8060808%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Custom UUID generator

2017-07-10 Thread Matt Hickman
If you look my_uuid_generator() is added to postgres at
https://github.com/rails/rails/blob/650ea5e5cf50d8a7242499463cf1762922d330a8/activerecord/test/cases/adapters/postgresql/uuid_test.rb#L186

You can add a stored procedure in a similar fashion in a migration.

--
Matt Hickman

On Sun, Jul 9, 2017 at 6:56 PM, <johnpearson...@gmail.com> wrote:

> Hi, I was reading the docs for primary key
> <http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/PostgreSQL/ColumnMethods.html#method-i-primary_key>
> on postgresql  and I saw that there was a way to add a custom stored
> procedure that returns a UUID. There is a test case as well that uses a
> custom uuid generator https://github.com/rails/rails/blob/
> 650ea5e5cf50d8a7242499463cf1762922d330a8/activerecord/test/
> cases/adapters/postgresql/uuid_test.rb#L193 but I wasn't sure how to to
> implement this myself.
>
> Like in the test case where do I place 'my_uuid_generator()' and how to
> implement it in my rails application?
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-talk+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/rubyonrails-talk/06bd9a3c-eafa-496b-a611-
> 2d35906517a3%40googlegroups.com
> <https://groups.google.com/d/msgid/rubyonrails-talk/06bd9a3c-eafa-496b-a611-2d35906517a3%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CALzpcTjCrkzdjNgYFv498m7WZ7v8gSQineoMS_gSuWOuw9cqhA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Dashboard with multiple controllers

2016-06-15 Thread Matt Martini
I have an application with items such as articles, bulletins, events, weekly 
specials,…   Each of these has its own MVC implmentation
and works well.  

What I would like to do is have the home page display a dashboard that contains 
many of these items, for example the last few articles,
a weekly special, upcoming events, and any bulletins with urgent news for the 
users.

How do I go about getting all of these things to appear on the page and in side 
bars?  Can I just render them from the layout (this doesn’t seem to work
but I could be doing it wrong), or use content_for?  

Please point me in the right direction.

Matt

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/46CAD6BC-BDA8-4462-A390-82617BE8C32E%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Application with dynamically/custom fields

2016-04-07 Thread Matt Jones


On Thursday, 7 April 2016 01:06:54 UTC-4, Jonatas Baldin wrote:
>
> Hi, I'm having trouble to create an application with dynamic fields. Could 
> you guys help me out?
> I'm not gonna write everything again, here's the stack overflow post and a 
> gist with what I got working and what's not.
>
> The links have the same content:
>
> http://stackoverflow.com/questions/36449947/application-with-dynamically-custom-fields
> https://gist.github.com/jonatasbaldin/906673980f847b30ec2cf6951dcb136e/edit
>
>
You'll want to read up on `fields_for`, which will help you build the 
required HTML inputs. I'd also recommend the Railscast on this 
topic: http://railscasts.com/episodes/196-nested-model-form-revised

Some other general notes on your Gist:

* has_many associations should be plural. Things will usually work with 
them named otherwise, but you may encounter odd behavior.

* the data model doesn't seem quite right - custom_field_infos should have 
a contact_id column and a custom_field_id column (to indicate which contact 
& field this record has data for). It shouldn't need a user_id column 
unless there's something else going on that's not mentioned in the Gist.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/be03e15d-56a5-417a-91cc-6c80bdbf3f66%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] How to match a literal colon in a route

2016-03-02 Thread Matt Jones
I did some digging on this, and I couldn't find a way to make this work 
with a literal in the route itself. 

Splatting works, though:

  get 'baz/*ark_tag/:id/bar' => 'welcome#index', constraints: { ark_tag: 
'ark:' }, as: :ark

will only match paths like "/baz/ark:/123/bar".

It's a little fussy with URL helpers, as you need to always specify ark_tag 
or you'll get an error:

  ark_path(ark_tag: 'ark:', id: 1234)

You'll probably want to define your own helpers that hide that.

The other, bigger issue is the OTHER features of the ARK spec that are 
going to confuse & annoy the default URL parser. In particular:

* the dot-separated components of VariantPath elements. The default Rails 
behavior appends a `.:format` optional parameter to the route. This 
*doesn't* allow further dots.

* the `?` and `??` suffixes. The single question-mark, in particular, is 
only detectable if you check the original request URI in the Rack request. 
I'm also unsure how to talk the regular path helpers into producing a 
single-question-mark URL.

If you're building an application which relies on complex routing of ARK 
URLs, you may want to consider writing your own Rack middleware to hijack 
the URL parsing process and transmute them into something more palatable to 
the existing router.

--Matt Jones


On Monday, 29 February 2016 20:21:19 UTC-5, Justin Coyne wrote:
>
> I'd certainly prefer not to, but it is prescribed by the ARK standard:  
> https://en.wikipedia.org/wiki/Archival_Resource_Key
>
> -Justin
>
> On Mon, Feb 29, 2016 at 5:45 PM, Hassan Schroeder <hassan.s...@gmail.com 
> > wrote:
>
>> On Mon, Feb 29, 2016 at 3:04 PM, digger250 <digg...@gmail.com 
>> > wrote:
>> > I'm trying to figure out how to escape a literal colon in the routes. 
>> If I
>> > make a route like this:
>> >
>> > get '/thing:/:id' => 'things#show'
>> >
>> > then '/thing:/123' does not match on this route
>> >
>> > I've also tried '/thing\:/:id' and '/thing%3A/:id' none seem to work.
>> >
>> > Does anyone have any tips here?
>>
>> Yes - don't do that  :-)
>>
>> See https://www.ietf.org/rfc/rfc1738.txt, specifically Section 2.2 on
>> reserved characters.
>>
>> --
>> Hassan Schroeder  hassan.s...@gmail.com 
>> 
>> http://about.me/hassanschroeder
>> twitter: @hassan
>> Consulting Availability : Silicon Valley or remote
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Ruby on Rails: Talk" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to rubyonrails-ta...@googlegroups.com .
>> To post to this group, send email to rubyonra...@googlegroups.com 
>> .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yDceABV646sh%2BH5L4uWoW%3D1Scc2ucj6ta4tYLU_q8JmRg%40mail.gmail.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/397a0487-c884-4f32-93de-48972ea47424%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] adding descriptions to images displayed in bluimp image gallery

2016-03-02 Thread Matt Jones
al-gallery-elements
>>  
>>
>> Walter 
>>
>> > 
>> > -- 
>> > You received this message because you are subscribed to the Google 
>> Groups "Ruby on Rails: Talk" group. 
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an email to rubyonrails-ta...@googlegroups.com. 
>> > To post to this group, send email to rubyonra...@googlegroups.com. 
>> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/rubyonrails-talk/ba8a9e19-aead-47d7-b7d1-0e516a6db7dc%40googlegroups.com.
>>  
>>
>> > For more options, visit https://groups.google.com/d/optout. 
>>
>>
> I still haven't gotten this working 
>

Since it's still not working, I'd recommend you start checking things 
one-by-one to verify they are working as you expect.

* does the gallery work *other* than the description field? Are there any 
errors / warnings in the browser console? If so, deal with those before 
moving on.

* add a breakpoint inside the 'onslide' handler the documentation provides. 
Are things as expected? Are the "text" and "node" variables getting what 
you'd expect?

* if everything looks OK but things still don't work, I'd recommend trying 
to create a smaller "test case" Rails application that demonstrates the 
issue. You'll get significantly better assistance from this list if you can 
provide a runnable example of the problem.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/f0ef7250-073d-46dc-b7b7-b9519cc8fb6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: I'm looking for a job as Ruby, Ruby on Rails developer.

2016-02-18 Thread Matt D
Any time!

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/084f6b35-c803-4df9-b00e-c71416e023ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Cron job for active_jobs

2016-02-18 Thread Matt D
Awesome, thanks. I'm a big fan of active_job, so I'm going to check this 
out.

On Monday, December 21, 2015 at 6:18:08 AM UTC-8, st0012 wrote:
>
> Hi, I recently working on a gem called ActiveJob-Cron 
> , it lets you to have recurrent 
> jobs when using ActiveJob. And I am also looking for help for solving this 
> gem's main issue: duplicate jobs 
> . So if you have 
> any opinion, please leave a comment or open an issue, I will very 
> appreciate it!
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/79577caf-1c7d-4ee2-92b7-5983d7b17964%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: I want eCommerce solution to my application where money can be transfer from buyer to seller

2016-02-18 Thread Matt D
No built in solution shipped with Rails. However, you may want to check out 
the Active Merchant gem, which supports many payment gateways to include 
PayPal.

On Thursday, January 14, 2016 at 3:49:35 AM UTC-8, Shaik Shavali wrote:
>
> Workflow:
>   Buyer can purchase a product from my application by using various 
> options like PayPal or CreditCard.
>   The money can be directly credited to the seller.
>   
>
>Is there any built in solution in Rails, Suggest me.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/5e96391c-5c04-47ef-b2fb-5533e621a5da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Rails with Foundation

2016-02-18 Thread Matt D
Are you talking about Zurb Foundation? If so, did you install Foundation 
via the gem?

On Monday, January 25, 2016 at 2:47:12 AM UTC-8, Jimmy Lin wrote:
>
> When I start using Rails with foundation. I followed the github starting 
> page.
> However, when I put the codes from Foundation official website page, it 
> will show different things.
> The top bar will not show as suppose. It will be four line with dots.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/7b8bf56b-320c-4b5b-99b3-220d19104052%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: I'm looking for a job as Ruby, Ruby on Rails developer.

2016-02-18 Thread Matt D
Hey Pavel!

Have you checked out:

   - https://weworkremotely.com, or
   - https://toprubyjobs.com


On Tuesday, February 2, 2016 at 2:03:25 PM UTC-8, Pavel Sh wrote:
>
> Hi guys, I'm looking for any job related with this technology.
>
> I have a 1 year of experience with RoR and 8 years as IT specialist 
> (generalist).
>
> Worked with:
>
> - Ruby, Ruby on Rails,
> - Rspec, TestUnit
> - Haml, Slim
> - JavaScript, Ajax, JSON
> - HTML, CSS/SCSS, Bootstrap
> - Gems (Devise, Pundit, Carrierwave, MiniMagick and others)
> - MySql
> - Git
> - VPS
>
> My GitHub with few examples: https://github.com/Pavel-A-S
>
> Location: Russia, Moscow
>
> English: Intermediate
>
> Email: pavel.a...@gmail.com 
>
> P.S. I will be glad to get any comments.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/c76ab4f4-d4a7-4b90-a370-15d19965fb09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: How to save a resume by click in rails

2016-02-18 Thread Matt D
Colin is right, we need more information. Where do you want the data saved? 

On Saturday, February 6, 2016 at 2:50:40 AM UTC-8, Ruby-Forum.com User 
wrote:
>
> I want to save a resume by clicking on this without database how can I 
> do this anyone can 
> help me please this purpose? 
>
> I also added a screen shot 
>
> below is my view file code: 
>
>
>   
> 
>  <%= res.first_name %> <%= 
> res.last_name %> - <%= res.current_address %> 
>  Preferred Job: <%= res.job_title %> 
>  Experience: <%= res.year_of_experience %> 
>  Education Qualification: <%= res.degree 
> %> 
> Institute Name: <%= res.institute_name %> 
> Save resume- Updated: <%= 
> res.created_at 
> %> 
> 
>  
>
> Attachments: 
> http://www.ruby-forum.com/attachment/11258/fshot.png 
>
>
> -- 
> Posted via http://www.ruby-forum.com/. 
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/99f5433d-f8cf-4c22-8315-fbda80131d03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: acts_as_votable ( aka acts_as_likeable)

2016-02-18 Thread Matt D
All votes are positive, so a vote is a "like." 

On Wednesday, February 3, 2016 at 4:29:50 PM UTC-8, fugee ohu wrote:
>
> I'm reading the docs for acts_as_votable (aka acts_as_likeable) and i 
> don't understand what's the difference between a vote and a like? although 
> the docs show how to assign, i couldn't find a test for if a model is liked 
> by a user or if a user likes a model 
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/a04ef57c-c4d2-426e-a33e-dc62d77aaeeb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: How to get Rails Internal IP

2016-02-15 Thread Matt Jones


On Saturday, 13 February 2016 05:15:29 UTC-5, Ruby-Forum.com User wrote:
>
> I am using a Rails 4 application, when in production mode i am getting 
> same IP address for all the members of the same organisation. The 
> requirement is to get different IP address for each member so as to 
> uniquely identify each system. 
>
> request.remote_ip 
> request.env['HTTP_X_REAL_IP'] 
> request.env["HTTP_X_FORWARDED_FOR"] 
>
> All these fetches me the same IP for each system. How can i uniquely 
> identify each system? Please help. 
>
>
`remote_ip` is calculated from the other two (and a few additional 
headers). The calculation may sometimes misunderstand the network topology, 
so if you're getting an IP that's part of your infrastructure (load 
balancers / proxies / etc) for every client it may be worth looking into.

Otherwise, your options are very limited. One of the *purposes* of 
organization-level NAT is to avoid leaking internal addresses / machine 
identities to the outside (for security). I've read of a way to use the 
Javascript WebRTC API to get the client's LAN address, but I wouldn't 
recommend depending on that for anything like licensing or authorization 
since any data coming from JS is trivially spoofable.

I'd recommend that you push back on whoever / whatever is imposing this 
requirement to figure out what the intent is. You may need to find an 
alternative way to achieve that goal.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/121d56da-5642-4cca-bdad-88e30b1012d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: rou

2016-02-12 Thread Matt Jones


On Tuesday, 9 February 2016 18:21:15 UTC-6, Ankit Raj wrote:
>
>
>
> On Wednesday, February 10, 2016 at 12:00:42 AM UTC+5:30, Matt Jones wrote:
>>
>>
>>
>> On Tuesday, 9 February 2016 12:20:37 UTC-6, Ankit Raj wrote:
>>>
>>> Hello geeks,
>>>
>>> Help me in solving following error.
>>>
>>>
>>> No route matches {:action=>"create_banner_text", 
>>> :controller=>"websites", :id=>nil} missing required keys: [:id]
>>>
>>> Detail is given on 
>>> https://gist.github.com/aj07/794468a5f6f92ea63dfb
>>>
>>>
>> On line 48 of the template, you have:
>>
>> create_banner_text_website_path(@website)
>>
>> The error indicates that @website is nil, so the 
>> create_banner_text_website_path route helper can't generate a URL.
>>
>> You didn't show the controller code, but that's where I'd recommend you 
>> start looking.
>>
>> --Matt Jones
>>
>
>
> my controller code 
>
>
[snip]
 

>   def load_website
> @website ||= current_ngo.websites.where(name: 
> params[:template]).first_or_initialize
>

Looks like I misinterpreted your error in my original reply. This line is 
the issue. If the call to `first_or_initialize` returns an unsaved object, 
then a route like

resources :websites, only: [:index, :create] do
  member do
get :create_banner_text 

isn't going to be able to generate a URL, since the unsaved object doesn't 
have an ID.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/2c4fc5e7-2685-439a-82db-ca2b7cb85900%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: rou

2016-02-09 Thread Matt Jones


On Tuesday, 9 February 2016 12:20:37 UTC-6, Ankit Raj wrote:
>
> Hello geeks,
>
> Help me in solving following error.
>
>
> No route matches {:action=>"create_banner_text", :controller=>"websites", 
> :id=>nil} missing required keys: [:id]
>
> Detail is given on 
> https://gist.github.com/aj07/794468a5f6f92ea63dfb
>
>
On line 48 of the template, you have:

create_banner_text_website_path(@website)

The error indicates that @website is nil, so the 
create_banner_text_website_path route helper can't generate a URL.

You didn't show the controller code, but that's where I'd recommend you 
start looking.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/df428f4c-cdd4-4503-93b2-3ef24a25ed1c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Dynamic Fields and Models Architecture

2016-01-26 Thread Matt Jones
The query interface you're describing sounds a lot like Elastic (formerly 
Elasticsearch): https://www.elastic.co/products/elasticsearch

--Matt Jones

On Tuesday, 26 January 2016 02:19:23 UTC-6, Usman Shahid wrote:
>
> Parsing isn't the issue. The problem is that I don't want to rewrite code 
> every time a new dataset is added. I want to provide an abstract interface 
> as well under which I can plug any data-set.
>
> On 25 January 2016 at 06:43, Walter Lee Davis <wa...@wdstudio.com 
> > wrote:
>
>> I would just make an importer to put all the data in a normalized set of 
>> fields in a single table. Then you can have one set of fields and one model 
>> to wrap around them. Parsing Excel is pretty easy these days, because it's 
>> just XML.
>>
>> Walter
>>
>> > On Jan 22, 2016, at 9:06 AM, Usman Shahid <usman@gmail.com 
>> > wrote:
>> >
>> > Ok, i'll explain this with a hypothetical scenario. Suppose the 
>> requirement is that we need to create a portal to provide stats of 
>> different products available in the market. And suppose you get data 
>> periodically from different places in spreadsheets.Each spreadsheet 
>> contains data for one kind of product, e.g cellphones, television etc and 
>> each kind of product has different fields. There can be hundreds of 
>> thousands of records in one spreadsheet so it must structured for efficient 
>> retrieval, however data is read-only, there'll be no write operations.On 
>> each data set we need to be able to perform generic, predefined read 
>> operations. e.g. selection of subsets fulfilling certain criteria, sorting, 
>> grouping, aggregates. For example, I should be able to write a generic 
>> functions, which gets table name, field name and returns count of unique 
>> values in that field. this can be used to count televisions with different 
>> resolutions and also to count books by different authors. here resolution 
>> and author is unique field of respective datasets.
>> >
>> > The problem I'm facing is that I've to create a different tables and 
>> respective models every time a new product type is added. Even though the 
>> models are essentially performing the same operations.
>> >
>> > Thanks for the response.
>> >
>> > Regards,
>> > Usman
>> >
>> > On 22 January 2016 at 00:33, Walter Lee Davis <wa...@wdstudio.com 
>> > wrote:
>> >
>> > > On Jan 21, 2016, at 2:25 PM, Usman Shahid <usman@gmail.com 
>> > wrote:
>> > >
>> > > It's not a performance issue. the problem is that i don't have one 
>> database, but multiple databases added at run-time. Each database is 
>> independent and I don't know what they look like however, i need to perform 
>> similar operation on each of them like taking averages, min, max, count, 
>> selections and other read operations. I want to be able to do this without 
>> making any changes to code when a new database is added. I'm thinking of 
>> going with a schema-less JSON based approach.
>> >
>> > How does that work? How are the databases added while the app is 
>> running? What does the adding? There's nothing in Rails itself that is 
>> going to help you do this (as far as I know). If the databases are being 
>> added by another process while the Rails app is running (remember -- 
>> production Rails apps only scan the database for structure once, at 
>> startup) then you're going to need that other process to kick off some 
>> notification to your Rails app so that it can be forced to reload and get 
>> the new structure. Otherwise, what it sounds like you need is some 
>> abstraction layer above the database layer so that you can talk to that 
>> through a single API, rather than relying on ActiveRecord for this. There's 
>> nothing magical about JSON or NoSQL storage engines for this, either. If it 
>> quacks like ActiveRecord, then it's designed to export its structure during 
>> app startup, and stick to that structure while it is running.
>> >
>> > Walter
>> >
>> > >
>> > > On 21 January 2016 at 19:24, Walter Lee Davis <wa...@wdstudio.com 
>> > wrote:
>> > > > On Jan 20, 2016, at 2:04 PM, Usman Shahid <usman@gmail.com 
>> > wrote:
>> > > >
>> > > > Hi Everyone,
>> > > >
>> > > > I've to design a system in which different datasets are added 
>> periodically to the system and user should be able to perform several 
>> predefined set of operations on the data. Dat

[Rails] Re: Has anyone setup Acts_as_Follower Gem Successfully?

2016-01-22 Thread Matt Jones


On Thursday, 21 January 2016 22:21:37 UTC-6, Ruby-Forum.com User wrote:
>
> Matt Jones wrote in post #1180578: 
> > On Tuesday, 12 January 2016 00:12:04 UTC-5, Ruby-Forum.com User wrote: 
> >> follow to unfollow. 
> >> 
>
> I'm returning for your advice and help. I've implemented a 
> Follows_Controller.Rb Below 
>
>
> class FollowsController < ApplicationController 
>   def create 
> @user = User.find(params[:user_id]) 
> current_user.follow(@user) unless current_user.blocked?(@user) 
>   end 
>
>   def destroy 
> @user = User.find(params[:user_id]) 
> current_user.stop_following(@user) 
>   end 
> end 
>
>
> The JavaScript create and destroy files for the AJAX buttons. 
>
> create.js.erb 
> $('#follow_user').html('<%= escape_javascript(render :partial => 
> "follows/follow_user", :locals => {:user => @user}) %>'); 
>
> destroy.js.erb 
> $('#follow_user').html('<%= escape_javascript(render :partial => 
> "follows/follow_user", :locals => {:user => @user}) %>'); 
>
> The follow user partial file. 
> <% if user_signed_in? %> 
> <% unless @user == current_user %> 
> <% if current_user.following?(@user) %> 
> <%= button_to('Stop Following', user_follow_path(user, 
> current_user.get_follow(@user).id), :method => :delete, :remote => true, 
> class: 'btn btn-danger-outline') %> 
> <% else %> 
> <%= button_to('Follow', user_follows_path(@user), :remote => 
> true, class: 'btn btn-success-outline') %> 
> <% end %> 
> <% end %> 
> <% end %> 
>
>
> Lastly, the routes. 
> resources :follows, :only => [:create, :destroy] 
>
>
> When I render the partial inside of the _posts.html.erb file, it gives 
> me an error. First it was 'user' method cannot be found, and then I used 
> the @user instead.


The behavior you've described doesn't match the code. The `:locals => { 
:user => @user }` part of those render calls should have made `user` 
available in the partial. If you're switching to using the instance 
variable, make sure to remove all the references to the local variable 
(there's still one in the call to `user_follow_path`).


Afterwards it started to say undefined method id for 
> nil:NilClass. Why am I unable to use the follow/unfollow buttons? 
>

That message isn't particularly helpful without a stack trace; something is 
calling `id` on an object that's nil. A stack trace would be helpful for 
finding the cause.

Regarding your followup message ("I want the buttons to show, but only 
redirect users that are not logged in."), that may require some rethinking 
of your approach. Doing a redirect from the `FollowsController#create` 
method will not do what you want (the browser will follow the redirect and 
attempt to parse the result as Javascript).

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/8a352428-2150-4646-96c2-a00aaaf1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Polymorphic join table not loading with includes

2016-01-14 Thread Matt Jones


On Wednesday, 13 January 2016 16:59:34 UTC-5, Flemming Thesbjerg wrote:
>
>
> I am trying to optimize a slow query with an includes statement. 
>
>
> But a join table with a polymorphic association seem to be preventing it.
>
>
> The following gist tries to illustrate the issue: 
> https://gist.github.com/flemse/fdd51ff5ad29a1f57134
>
>
> When running the code from the gist it will fail to load the join table 
> and therefore fail.
>
>
> Any help would be greatly appreciated.
>

It would be helpful to see the exact SQL generated when the tests in that 
Gist run. People can run the example, but it's an extra step.

The query fails because the `post_artifacts` table isn't joined. This is an 
expected behavior of `includes`; it chooses between a preload (which 
requires one additional query but fewer joins) and an eager load (which 
widens the query with a join). To do this, it relies on checking to see if 
the included tables are referenced in the SQL. Putting conditions on the 
join table (post_artifacts, here) in a through association (a_comments, 
here) without hinting will cause this behavior. 

There are at least two ways to work around this problem:

* first alternative: explicitly build an association of PostArtifacts that 
have the condition applied. Change the Post model to:

class Post < ActiveRecord::Base
  has_many :post_artifacts
  has_many :comments, through: :post_artifacts, source: :artifact, 
source_type: 'Comment'
  has_many :a_post_artifacts, -> { a }, class_name: 'PostArtifact'
  has_many :a_comments, through: :a_post_artifacts, source: :artifact, 
source_type: 'Comment'
end

This moves the condition to a place where ActiveRecord understands the 
`post_artifacts` table will be referenced when preloading `a_comments`. The 
resulting SQL looks like:

SELECT "posts".* FROM "posts"
SELECT "post_artifacts".* FROM "post_artifacts" WHERE 
"post_artifacts"."rule" = ? AND "post_artifacts"."artifact_type" = ? AND 
"post_artifacts"."post_id" = 1  [["rule", 0], ["artifact_type", "Comment"]]
SELECT "comments".* FROM "comments" WHERE "comments"."id" IN (1, 2, 3, 4, 
5, 6, 7, 8, 9, 10)

* second alternative: explicitly specify `references` at the callsite. 
Leave the associations as-is from the Gist and change the second assert in 
the test to:

assert_equal 10, 
Post.includes(:a_comments).references(:post_artifacts).flat_map(&:a_comments).count

This uses `references` to inform ActiveRecord that loading the requested 
Posts also requires post_artifacts.

The generated SQL looks different than the previous case, as `references` 
forces eager-load instead of preload:

SELECT "posts"."id" AS t0_r0, "posts"."title" AS t0_r1, "comments"."id" AS 
t1_r0, "comments"."content" AS t1_r1 FROM "posts" LEFT OUTER JOIN 
"post_artifacts" ON "post_artifacts"."post_id" = "posts"."id" AND 
"post_artifacts"."artifact_type" = ? LEFT OUTER JOIN "comments" ON 
"comments"."id" = "post_artifacts"."artifact_id" AND 
"post_artifacts"."rule" = ?  [["artifact_type", "Comment"], ["rule", 0]]



One thing that *doesn't* work yet: specifying `references` in the scope 
passed to `has_many`.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/ec529f36-54d5-40b8-8f8d-2b406f186e08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Has anyone setup Acts_as_Follower Gem Successfully?

2016-01-12 Thread Matt Jones


On Tuesday, 12 January 2016 00:12:04 UTC-5, Ruby-Forum.com User wrote:
>
> If you happen to have a complete solution for setting up 
> Acts_As_Follower Gem. Please, post it for your fellow devs. 
>
> https://github.com/tcocca/acts_as_follower 
>
> Users_Controller.rb [content] 
> Routes.rb [content] 
> _follow.html.erb [button] 
> JS for sending AJAX request and changing the state of the button from 
> follow to unfollow. 
>
>
A quick word of advice: try looking for things before asking here. For 
instance, the FIRST HIT on Google for the query "acts_as_follower ajax" 
(without quotes) is this:

https://gist.github.com/tcocca/863091

The comments on that Gist appear to imply that not all of it will work on 
Rails 4. I didn't see anything that jumped out as being deprecated / 
removed between 3 and 4 but I haven't tried it out. I'd recommend you try 
that code and report back if there are problems you can't sort out.


Lastly, adding a block button and unblock button. 
>

Again, you'll get much better assistance here if you try things yourself 
first. If you want requirements turned directly into code, email me 
off-list and let me know where to send the INVOICE. :)

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/f3df4cf8-9ff1-4f1e-879f-36873917475f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Get a username when using Devise and Omniauth

2015-12-30 Thread Matt Jones


On Tuesday, 29 December 2015 16:28:32 UTC-5, Michael Prieto wrote:
>
> Hello everyone o/
>
> I'm currently building a Rails app and I'm using Devise 
> <https://github.com/plataformatec/devise> and Omniauth 
> <https://github.com/intridea/omniauth> (Google OAuth2 and Facebook) for 
> authentication. All users are going to have unique usernames. This is not a 
> problem when I'm using just a form, but when the users tries to sign up 
> using Omniauth, I can't get a username that I can ensure is unique and fits 
> the criteria I've made for a valid username. If I do try to sign up with 
> it, it just redirects to the form that regular users would use to sign up.
>
> I've thought about redirecting the user to a separate page where they 
> create a username, but I don't know how I would go about this. Searching 
> the internet has not yielded any results either. 
>
> Does anyone know how I could accomplish this? I'm open to any ideas.
>
>
One way I've done similar things is by overriding 'after_sign_in_path_for'. 
See the Devise docs for an example:

https://github.com/plataformatec/devise/wiki/How-To:-redirect-to-a-specific-page-on-successful-sign-in#redirect-back-to-current-page-after-oauth-signin

Based on the requirements you've described, one option would be to check on 
sign-in to see if a user has no username and redirect them to a page that 
requests one. Your DB models may require some work to make it possible to 
create a "user" with an empty username.

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/acd4eb84-b8ee-46f6-beba-1c384b3758dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Covert Hijiri Date to Gregorian Date

2015-12-17 Thread Matt Jones


On Wednesday, 16 December 2015 03:36:09 UTC-5, honey ruby wrote:
>
> Hi, I want to convert Hijiri Date to Gregorian Date I have tried gem 
> 'hijri2greg_date' but it is not showing correct Gregorian date. Is there 
> any other gem which converts correctly and best way.
>
> Thanks in advance
>

You may get more assistance if you post an example of the conversion code 
that's failing.

I can't speak to the accuracy, but the gem at 
https://github.com/ecleel/hijri at least has tests. 

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/db0661d2-f5c5-47cb-92cc-187568519e98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: create/unload runtime routes

2015-12-11 Thread Matt Jones


On Thursday, 10 December 2015 16:48:28 UTC-5, mark wrote:
>
> Hi,
>
> I am trying to create routes at runtime but I am finding this a but of a 
> challenge. I can get it to register as a route using the code below but 
> then when url_for( with_url_options ) is called it throws an on any 
> different fout error:
>
> No route matches {:action=>"index", 
> :controller=>"admin/scientific_review_processes__1__1s"
>
> When I try to load a different meta model/controller/route I have to 
> stop/start the server and it will work. I want to be able to load and 
> unload controllers/models and routes at runtime but I have yet to make this 
> work correctly. 
>
>
I'm missing something - why is this something that needs to happen at 
runtime versus at application startup?

The code you show below can't be the whole solution, since it's going to be 
creating routes to controllers that either existed at application startup 
(in which case the routes could just be in routes.rb) or that are being 
conjured into existence at runtime (tricky, and likely to cause exciting 
thread-safety issues on some application servers).

--Matt Jones

 

> private
> def create_route(table_name)
>
> #  if 
> Rails.application.routes.named_routes.routes["admin_#{table_name}".to_sym].nil?
> Rails.application.routes.disable_clear_and_finalize = true
>
>   Rails.application.routes.draw do
> namespace :admin do
>   resources table_name.to_sym do as_routes end
> end
>   end
>   #binding.pry
>   #Rails.application.routes.finalize!
>   #  ActiveSupport.on_load(:action_controller) 
> {Rails.application.routes.finalize! }
> #  end
> end
>
> Does anyone know what would make such a thing work in a runtime 
> environment? 
>
> Thanks in advance,
> Mark
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/879f03ff-982e-44ea-8e9c-095a7764aab6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Failure to install or update any gem through Win CMD

2015-12-11 Thread Matt Jones


On Monday, 30 November 2015 08:24:15 UTC-5, Ruby-Forum.com User wrote:
>
> Hello, 
>
> I've been trying to install and update different gems to work with Ruby 
> on Rails, but keep getting the same error, apparently indicating I can't 
> install or update any gem: 
>
> I generally type in something like: 
>
> gem update --system or gem install Rails --version 4.0.0 --no-ri 
> --no-rdoc 
>
> And get the following: 
>
> ERROR: While executing gem ... (Errno::EINVAL) 
> Invalid Argument - socket(2) - udp 
>
> Note that I've proceeded to the same setup just a couple of days before 
> on a different machine and had no problem. 
>
> I couldn't figure any place where this same Error was explained or 
> encoutered. 
>
>
The error you've described looks a lot like this one:

https://github.com/rubinius/rubinius/issues/2929#issuecomment-34701873

Can you run the script linked there and paste your output? 

Since this is (potentially) a networking issue, any information about your 
setup (system version, network config, any proxies in use, etc) would be 
useful.

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/90276c43-c004-49a3-b071-23b2e75cab4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Dynamic Links within a namespace

2015-11-09 Thread Matt Jones


On Monday, 9 November 2015 09:27:52 UTC-5, Ruby-Forum.com User wrote:
>
> Hello all! 
>
> I am new to all of this and I am trying to accomplish something, and I 
> am hoping that someone will be able to assist me… 
>
>
> I am trying to set up a namespace within a dynamic link. I have created 
> an admin namespace and I need to following link to go to 
> ../admin/people/xxx 
>
>  
>   <%= link_to(person) do %> 
>  <%= person.fname %> <%= person.lname %> 
>   <% end %> 
>  
>
> Am I missing something from the controller or what? How do I get this 
> dynamic link to go to the namespace route and not the base page? Does 
> something go in the <%= link_to(person) do %> and if so what? I am just 
> so new to all of this, I am not sure how to solve this problem. 
>

This isn't mentioned in the `link_to` documentation, but looking at the 
source it appears you can pass the same sort of thing you'd give 
`polymorphic_path` to get namespace routes.

http://api.rubyonrails.org/classes/ActionDispatch/Routing/PolymorphicRoutes.html

So something like `link_to([:admin, person]) do` in your example should do 
the trick.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/a5bd6b0b-22fa-475c-877b-a1dae26c253b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Login modal using default rails ajax request not working with subdomains

2015-10-21 Thread Matt Jones


On Friday, 16 October 2015 03:37:03 UTC-4, Ruby-Forum.com User wrote:
>
> I am having a devise user model. 
>
> To login I am using twitter-bootstrap modal.The modal is by default 
> hidden and shown only after an rails default ajax request is send to the 
> server. 
>
> It works fine with localhost and production. But when a user is on a 
> subdomain(using acts_as_tenant) like business.lvh.me:3000 the modal 
> window does not pop up and the ajax request fails. 
>
> I am sharing the session across all the domains. 
>
> My SessionStore initializer. 
>
> > Rails.application.config.session_store :active_record_store, :key => 
> > '_my_app_session',domain: 'lvh.me' 
>
> PFB the error.log for the same. 
>
>   Rendered remote_content/_remote_sign_up.html.erb (78.8ms) 
>   Rendered remote_content/remote_sign_up.js.erb (86.2ms) 
> Security warning: an embedded 

Re: [Rails] Code to be run on server start up

2015-10-20 Thread Matt Jones


On Friday, 16 October 2015 12:30:45 UTC-4, Mike Witt wrote:
>
> On 10/16/2015 09:21:44 AM, Hassan Schroeder wrote: 
> > On Fri, Oct 16, 2015 at 8:46 AM, Mike Witt <msg...@gmail.com 
> > wrote: 
> > > In Rails 4.2, is there a place where I can put code that I want to   
> > be called 
> > > immediately after the rails server starts up 
> > 
> > Initializers are called *during* startup; would that do? 
>
> I'm not sure. Would I have access to the database, either through   
> ActiveRecords or ? 
>
> Pardon my ignorance here. I'm not sure where to find documentation   
> concerning the "transition" between getting all the framework   
> initialized and the "normal" rails stuff where you're just responding   
> to http requests one-by-one. 
>
>
As you've noted, config/initializers is the right place for this. For 
reference or general curiosity, there's a detailed guide to the Rails 
initialization process here:

http://guides.rubyonrails.org/initialization.html

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/98514966-9794-4b03-a526-554fff17da52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Running a Ruby Script from Rails controller kills the rails server

2015-10-13 Thread Matt Jones


On Tuesday, 13 October 2015 07:56:28 UTC-4, Sam S wrote:
>
> I am trying to run a ruby script from my rails controller.
> The script runs successfully when the rails server is started normally as
>
>  rails s thin -e development 
>
> But when rails server is started as a daemon, the ruby script fails to run.
>
>  rails s thin -e development -d
>
> Inside the controller the ruby script is run with  the **exec** command.
>
>  script_exec = exec("ruby 
> /Code/AttendanceReport/attn/bin/scripts/Spreadsheet_proper.rb '#{city}' 
> '#{date1}' '#{date2}'")
>
>
>
> The above approach kills the rails server and doesn't execute the ruby 
> script. And hence I used
>
>  script_exec = %x{ruby 
> /Code/AttendanceReport/attn/bin/scripts/Spreadsheet_proper.rb '#{city}' 
> '#{date1}' '#{date2}' }
>  
>   script_exec = system("ruby 
> /Code/AttendanceReport/attn/bin/scripts/Spreadsheet_proper.rb '#{city}' 
> '#{date1}' '#{date2}'")
>
> The above **%x** and **system** approaches also fail when run rails server 
> is started with -d. 
>

How do they "fail"? Is there any output in the terminal, in the system log, 
or the Rails server logs? If you wrap the call in a begin/rescue block, 
what is the value in $? Example:

exec_result = begin
  system("do a thing")
rescue => e
  $stderr.puts(e.inspect)
  $stderr.puts($?)
  exit(-1)
end

Also, I'd recommend being VERY CAREFUL with string interpolation around 
strings that are handed off to the shell (as the one-argument version of 
`system` does). If someone enters their city as "; rm -rf / ; echo" you're 
going to have a very bad time, depending on your system's permissions. 
Prefer the multi-argument version of `system` whenever possible:

system("command name", "arg1", "arg2", "arg3")

In this form, the arguments are passed straight through to the called 
program, without ever being expanded / manipulated by the shell.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/74646212-663b-4679-b4fe-88f3f5d7616d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Having some problems getting my params to pass. Any help would be super appreciated..

2015-10-13 Thread Matt Puerkel


I am trying to pass parameters from an "Events" controller, to an 
"Invitations" controller and from the Invitations#new to the 
Invitations#create views. I think I'm pretty close to getting this wrapped 
up bit keep getting: "param is missing or the value is empty: " errors when 
I run it.


In order to pass the event.id from the Event#show view I am doing the 
following through the "Invite Guests" link.


events/show.html.erb

<% @user.owned_events.each do |e| %><%= e.name %>  |  <%= link_to 
"Invite Guests", invitations_new_path(:event_select => e.id) %>



That should pass the current event selected as event_select.

I am then using that event id as well as all of the user ids(minus the 
current_user) to create a list of possible invitees.


invitations_controller.rb:

class InvitationsController < ApplicationController
helper_method :current_user

def new@event_selected = Event.find(params[:event_select])@users = 
User.where("id != ?", current_user.id )end
def create@invitation = Invitation.new(invite_params)end

private
def invite_params
params.require(:attended_event_id => params[:event_selected], :attendee_id => 
params[:user_ids].first )
 end
end



My view showing the list of users and after selecting a checkbox, should 
pass the event_selected and user_ids.


invitations/new.html.erb

Invite users to <%= @event_selected.name %>
<%= bootstrap_form_for Invitation.new do |f| %>
  
<% @users.each do |user| %>

  <%= hidden_field_tag :event_selected, @event_selected.id %>
  <%= check_box_tag 'user_ids[]', user.id %>
  <%= h user.name %>
  
  <% end %>
  <%= submit_tag "Invite Selected Users" %><% end %>


I am trying to get this to work to select just a single user at a time 
before moving to create multiple objects from the selected event combined 
with all the results in the user_id array. When I select a single user I 
keep getting the missing param error but looking at the hash, it seems like 
everything is there.

param is missing or the value is empty: {:attended_event_id=>"14", 
:attendee_id=>"3"}

Parameters:

 {"utf8"=>"✓",
 
"authenticity_token"=>"GMMg9DwnTRAw4qP/ICqgACUB4d42Pl9Y7hrrNQzO38K8inbgyM00H2etrepjrT35hwIenHfwQPQW08V6QnHl1A==",
 "event_selected"=>"14",
 "user_ids"=>["3"],
 "commit"=>"Invite Selected Users"}


Pretty new at this coding thing but this is the first problem I haven't 
been able to solve through a lot stackoverflow searches. I seem to be 
missing something here and I'm sure it's just a simple thing. Then again I 
could be completely missing the mark trying to go about this without 
following a bit more guided path... 




-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/e45f7bac-39cf-4342-b029-a1f4106fe830%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Too many sessions in a rails 4 app.

2015-10-12 Thread Matt Jones


On Saturday, 10 October 2015 15:57:25 UTC-4, Ruby-Forum.com User wrote:
>
> I am building an E-commerce website on ruby on rails from scratch. 
>
> My product belongs to a subcategory which in-turn belongs to a category. 
>
> My filters partial include multiple check-boxes for 
> category,subcategory,additional_category(Like hand made clothes,factory 
> built etc.),lifestyle(relaxed,corporate etc) and 
> cloth_material_type(this has around 30 options) 
>
> I am sending an array for each of these 5 cases to the backend to search 
> through the associations. 
>
> Now when a non logged in user reloads the page the filters set by user 
> resets to default. 
>
> To avoid this I have three options in mind. 
>
> Option 1. Store the filter values set by the user in the cookies which 
> is fast.But it might slow down the user's browser. 
>
> Option2 . Store the values in a session using ActiveRecord::SessionStore 
> gem which will increase the size of session for me to 65K but would slow 
> down the application. 
>
> Option 3 .Using jquery modify/create document.url options so that every 
> filter option gets appended to the document.url and on reload I get the 
> parameters set by the user for filtering.But this looks very cumbersome 
> to implement. 
>
>
This isn't terribly difficult to implement, especially if you're reloading 
the page when the products are filtered - just make the form use `GET` and 
the URL will have all the user's selections. This is also helpful for users 
who want to bookmark or share the filtered list, as the entire state of the 
view is encoded in the URL.

--Matt Jones
 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/dc201497-ff44-4bc5-b0a8-b3037951cdb1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Could not find gem 'tzinfo-data (>= 0) x86-mingw32'

2015-10-08 Thread Matt Jones


On Thursday, 8 October 2015 12:09:54 UTC-4, arif ullah wrote:
>
>
> <https://lh3.googleusercontent.com/-P7ajHakCiA4/VhaO9jtqtMI/CGE/LqtdqI-ib9E/s1600/r2.JPG>
>
>
> <https://lh3.googleusercontent.com/-bvtp4_v1zwQ/VhaO6n0rcRI/CF8/MN7uwCOqqxA/s1600/r1.JPG>
>
>
> <https://lh3.googleusercontent.com/-lHwM8U0Vgtc/VhaPupqNM1I/CGQ/f7oHOEc7Tsg/s1600/r3.JPG>
>
> So many time i'm trying to solve this problem,but still now i'm failed. 
> I'm using windows 10
>
>
> Please help me to solve this problem.   
>

First off, don't post screenshots. They get hidden by default in the Google 
Groups interface, and they're just harder-to-read pictures of text you 
could have copied directly.

Secondly, the first error message says: "Run `bundle install` to install 
missing gems." Have you tried that yet? If so, what happens?

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/a419b791-dadd-418e-a562-1cc156708666%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Active Record has_one through

2015-10-08 Thread Matt Jones


On Wednesday, 7 October 2015 20:47:54 UTC-4, Ruby-Forum.com User wrote:
>
> I have two tables in my app which I am attempting to relate through a 
> join table.  The Artist class which uses 'has_many through', works as 
> expected.  However, the Event class using 'has_one through', brings back 
> nil. 
>
> class Artist < ActiveRecord::Base 
>   has_many :artist_events, dependent: :destroy 
>   has_many :events, through: :artist_events 
> end 
>
> class Event < ActiveRecord::Base 
>   belongs_to :artist_event 

  has_one :artist, through: :artist_events 
>

Something hasn't been copied correctly here, because this shouldn't work - 
the `through` refers to an association (artist_events) that doesn't exist 
on Event.

As noted elsewhere, `belongs_to` is likely not the right association to use 
here; it's expecting an 'artist_event_id' column on the 'events' table.

You'll also want to carefully consider if `has_one` is the right 
association as well. The table structure you've set up (Artist / 
ArtistEvent / Event) is a classic many-to-many relationship. If an Event 
can truly only have one artist, this structure is not needed. If an Event 
can have many artists, than a has_one isn't correct.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/2fa1934c-fe96-42e6-bcb2-fa4575d30f8a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: How to write code to search serialize object in rails3 with PG sql

2015-10-07 Thread Matt Jones


On Tuesday, 6 October 2015 13:54:40 UTC-4, Arvind Vyas wrote:
>
> My code is this 
> {"1"=>"5", "2"=>"test", "3"=>"tes"}}, 
> view_cout: 1>
>
> How I can write code to search project from "my_data" key or value ?
>
> I have search and found there is one way by hstore we can achieve it ( 
> https://github.com/diogob/activerecord-postgres-hstore) but in this sense 
> I have to change current logic of storing data also I have to move the 
> current data to new fild if I use this.
> Is there any good way which take less changes or 
> if not then what should I do to create filter for it.
>

You might want to consider the Postgres JSON support - it will allow for 
queries deep into the data.

BUT you should first think hard about whether this should be a serialized 
field at all; one of the primary tradeoffs you make with serialized fields 
vs. storing the data broken out into related records is *searchability*. If 
you're going to be querying the values extensively, maybe an alternative 
approach within your DB is better - or perhaps even a secondary indexing 
system (Solr / ElasticSearch / etc).

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/f31e08f1-95b3-44af-b4d2-d19513aeb227%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: ERROR: While executing gem (Errno::ECONNREFUSED) Connection refused - recvfrom(2)

2015-10-05 Thread Matt Jones


On Thursday, 24 September 2015 17:21:05 UTC-4, Ruby-Forum.com User wrote:
>
> Hello I'm trying to install bundler using this command 
>
> gem install bundler 
>
> Once i run the command this comes out 
>
> ERROR:  While executing gem ... (Errno::ECONNREFUSED) 
> Connection refused - recvfrom(2) 
>
> Attachments: 
> http://www.ruby-forum.com/attachment/5/Untitled1.png 
>

The typical cause of this issue is something that makes an SSL connection 
to rubygems.org fail. It's hard to say more without additional information: 
your copy of Ruby may have been installed without OpenSSL, the certificate 
that issued the one used by Rubygems.org may not be trusted by your 
machine, a proxy server along the way could be misconfigured.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/44cd1b3b-7255-4297-ae4e-38494d820fc3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Sorcery Activity loggings

2015-10-01 Thread Matt Jones


On Friday, 25 September 2015 10:17:36 UTC-4, Hans wrote:
>
> Thanks for your replay
> However as sorcery is a gem and the update of last_activity_at and last 
> login_at is made from inside the gem I cannot add the explain command. Here 
> is some relevant log outputs
>
> [1m [36mSQL (75.3ms) [0m   [1mUPDATE `users` SET `last_login_at` = 
> '2015-09-25 11:22:12' WHERE `users`.`id` = 1 [0m
> [1m [35mSQL (40.0ms) [0m  UPDATE `users` SET `last_activity_at` = 
> '2015-09-25 11:22:12' WHERE `users`.`id` = 1
>
> to be compared with
> 1m [35m (0.3ms) [0m  UPDATE `users` SET `visits` = 1124, `updated_at` = 
> '2015-09-25 11:22:12' WHERE `users`.`id` = 1
> where I do about the same thing in my application
>
>
75ms and 40ms seem wildly out of line for updating a single row in a table 
with only 6000 rows. Can you provide more specifics on how the application 
server and database server are set up? In particular, how long does it take 
for a simple `ping` to get from the application server to the database?

--Matt Jones
 

> Den fredag 25 september 2015 kl. 15:16:44 UTC+2 skrev Albert Ramstedt:
>>
>> Hello Hans!
>>
>> In order for anyone to help you (who might not be experienced with 
>> sorcery), a lot more information is needed. But perhaps just some debugging 
>> hints would be helpful:
>>
>> Could you write the output from the SQL (and a explain analyze of this 
>> query) that is triggered with the update. Are there any callbacks (or 
>> database-level triggers, index updates) doing stuff in an update, or is it 
>> only the sql that takes time?
>>
>> An update to a table of 6000 rows should not take close to that time to 
>> just update a date. But there might be other stuff happening when you do 
>> this.
>>
>> Albert
>>
>>
>> On Fri, Sep 25, 2015 at 2:27 PM, Hans <hans.m...@klockholm.se> wrote:
>>
>>> I am now refactoring and optimizing my code and noticed that the calls 
>>> to update last_activity_at varies between 50 and 100 ms.
>>>  I think is is too much to be ok för a simple update.
>>>
>>> Have others different or the same experience of sorcery ?
>>>
>>> My user table has 6000 rows and 36 fields. (too many - should be 
>>> refactored anyhow). 
>>>
>>> Can the slow response times depend on this table, sorcery, the server or 
>>> the rest of application
>>>
>>> What is wrong ?
>>>
>>>
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Ruby on Rails: Talk" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to rubyonrails-ta...@googlegroups.com.
>>> To post to this group, send email to rubyonra...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/rubyonrails-talk/1e57391f-fe96-47ec-ae56-ab918ae75a1f%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/rubyonrails-talk/1e57391f-fe96-47ec-ae56-ab918ae75a1f%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/ff65b925-8ae2-4fef-b357-b3fda05ea8e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: reset association cache for polymorphism

2015-09-20 Thread Matt Jones


On Saturday, 19 September 2015 12:03:47 UTC-4, Oto Iashvili wrote:
>
> Hi,
>
> I have a product class with category and  a polymorphic attributes 
> details_info, that depending on category go to one or another table to get 
> the detail
>
>
> Class Product
> category
> details_info
>
> end
>
> Class DetailsInfo
> ...
> end
>
> Class Pencil
>
>   include DetailsInfo
> type
> color
> end
>
> Class Notebook
>
>   include DetailsInfo
> size
> ...
> end
>
> and to display products i do
> prds = Products.all
> prds.each do |pr|
>
> if pr.category == 'pencil'
> DetailsInfo.table_name = 'pencil'
>
> else if pr.category == 'notebook'
>
> DetailsInfo.table_name = 'notebook'
> end
>
> end
>
> (this is just kind of algo I use)
>
> All this was working fine but with rails > 4.2 , it doesnt work anymore.
> The first time pr.details_info will be called, it seems that the table 
> name is cached somewhere, and then all other products are using the same 
> table_name. When I check during loop, I can see that DetailsInfo.table_name 
> is always correct, but still when pr.details_info will be called , it used 
> the first table_name that was used. I can also see that the method 
> table_name is called every step of the loop, and it return the good 
> table_name, but still, the sql request search on bad table.
>
> How can I reset that ? Ive tried a lot a thing like 
> emptying association_cache, also different things 
> with reflect_on_all_associations, reset_column_information, reload, ...
>
>
As mentioned on rails-core, I'd recommend looking into polymorphic 
associations for this. Here's a possible example:
```
  class Product < ActiveRecord::Base
# the products table has two columns relevant here:
#   * details_info_id, integer
#   * details_info_type, string
belongs_to :details_info, polymorphic: true
  end

  class Pencil < ActiveRecord::Base
has_many :products, as: :details_info
  end

  class Notebook < ActiveRecord::Base
has_many :products, as: :details_info
  end
```

Given those models, if you retrieve a list of Product objects you should be 
able to access each one's `details_info` from the correct tables.

If you're still unsure how to proceed, more detail on the specifics of your 
schema and desired functionality would be useful.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/5e25fdf7-b166-4e84-956b-645cb62dd3e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: how testing associated objects?

2015-09-02 Thread Matt Jones


On Tuesday, 1 September 2015 14:40:39 UTC-4, Ruby-Forum.com User wrote:
>
> please help solve the problem. 
>
> poll controller: 
>
> class PollsController < ApplicationController 
>   def index 
> @user = User.find(params[:user_id]) 
> @polls = @user.polls.paginate(page: params[:page], :per_page => 
> 10).order(title: :DESC) 
>   end 
> end 
>
> route: 
>
> user_polls GET/users/:user_id/polls(.:format) 
> polls#index 
>
> polls_controller_spec.rb: 
> RSpec.describe PollsController, type: :controller do 
>   describe "GET #index" do 
> before :all do 
>   @user = FactoryGirl.create(:user) 
> end 
>
>
> it "assign user as @user" do 
>   get :index, user_id: @user.id 
>   expect(assigns(:user)).to eq(@user) 
> end 
>
>
> it "assigns polls as @polls" do 
>   get :index, user_id: @user.id 
>   expect(assigns(:polls)).to eq([@poll]) 
> end 
>
>
> it "redirects to the index view" do 
>   get :index, user_id: @user.id 
>   expect(response).to render_template("index") 
> end 
>   end 
> end 
>
> after run tests, i get follow error message: 
>
> kalinin@kalinin ~/rails/phs $ rspec 
> spec/controllers/polls_controller_spec.rb 
> .F. 
> Failures: 
>   1) PollsController GET #index assigns polls as @polls 
>  Failure/Error: expect(assigns(:polls)).to eq([@poll]) 
>expected: [nil] 
> got: # 
>(compared using ==) 
>Diff: 
>@@ -1,2 +1,2 @@ 
>-[nil] 
>+[] 
>  # ./spec/controllers/polls_controller_spec.rb:16:in `block (3 
> levels) in ' 
>
> Finished in 1.23 seconds (files took 2.81 seconds to load) 
> 3 examples, 1 failure 
> Failed examples: 
> rspec ./spec/controllers/polls_controller_spec.rb:14 # PollsController 
> GET #index assigns polls as @polls 
>
>
> as you can see problem in test 'assigns polls as @polls'. I do not 
> understand why array @polls is empty 
>
>
Unless you accidentally removed it when posting here, you aren't creating 
any Poll records. `@poll` is also not set to anything...

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/21d88a9b-7ea1-4bf8-9b9e-3858f62da80c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: importing .csv file from user and storing data of csv into database using ruby on rails.

2015-08-27 Thread Matt Jones


On Monday, 24 August 2015 04:28:12 UTC-4, iampravee...@gmail.com wrote:

 Hi friends , I am modifying virtualX open source application. I wanted to 
 introduce new functionality that is uploading questions from .csv file and 
 storing those questions to the database. I am very new to ruby this task 
 becomes very tough for me . So i referred so many websites and blogs and i 
 ready some code for this feature . but this is code is not working . I am 
 getting HTTP 500 error . As i checked code in Aptanan Studio , it is 
 showing some errors. 


In future, please also post the errors; since this isn't all the code in 
your application we can't run it to see what happens, and are relying on 
you to tell us.
 

 I am posting my code over here . Please help me friends . I am really not 
 getting what is happening . 

 I am using Ruby  1.8.7 
 Rails 3.0.3


  
 questions_controller.rb

 def import
 
@question = Question.new
@question.import(params[:file])


You've defined the import method below as a class method (`def 
self.import`) but are attempting to call an instance method here on 
`@question`.

The two lines above should likely be:

Question.import(params[:file])

 

 redirect_to root_url, notice: Questions imported succefully.
   end

 questions.rb

 def self.import(file)
 CSV.foreach(file.path, headers: true) do |row|

 question_hash = row.to_hash 
 @question = Question.where(id: question_hash[“id”])


Double-check your source file: the line you've pasted here has slant-quotes 
(“ and ”) which are not the same thing to Ruby as a straight double-quote 
(). It's also possible that these were adding while composing the email.

 

 if @question.count == 1
 @question.first.update_attributes(question_hash)
 else
 Question.save!(question_hash)



What is the intent of this line? Are there situations where you can have 
multiple `Question` records with the same ID? There is not a class method 
called `save!` built into ActiveRecord.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/8f92e388-a655-4489-aaa1-badd7370a74c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Arabic text showing not properly in the file of s3

2015-08-24 Thread Matt Jones


On Friday, 21 August 2015 08:24:46 UTC-4, amtest wrote:

 Thanks matt, can you suggest me to do any work around for this, i have 
 been sitting with these issue for some days? the default encoding in my 
 application is config.encoding = utf-8


My suggestion would be to go through all the code that's handling this data 
and verify that the values are correctly-encoded. For instance:

* is the data coming into the system from the user correctly encoded?

* is the database column the data is stored in correctly encoded? 

* is the code that writes the CSV setting the correct encoding?

Corrupted data earlier in the process will generally be passed straight 
through subsequent steps, so troubleshooting starting from the end (the CSV 
file on S3) is going to be difficult.

--Matt Jones
 

 On Friday, 21 August 2015 15:55:00 UTC+4, Matt Jones wrote:



 On Thursday, 20 August 2015 06:03:13 UTC-5, amtest wrote:

 I have uploaded the csv to s3 with rails, but the issue is, that the 
 file have arabic names, so when i open that csv file directly from s3 
 console, its showing the arabic names as gibberish, i have attached that 
 *image* here



 https://lh3.googleusercontent.com/-7MUHzpfGKls/VdWzcCb2WkI/AY8/k_hYB0rIqrw/s1600/Screen%2BShot%2B2015-08-20%2Bat%2B2.16.55%2BPM.png

 also i tried to add that charset utf, but its showing as same, is 
 there any workaround for this? 

 url = object.url_for(:read, {expires: E::EXPIRE,
  :content_type = text/csv;charset=utf-8, 
 response_content_disposition: attachment;filename=#{filename[0]}.csv 
 }).to_s


 You may need to verify the data is not already corrupted in the CSV. The 
 text you've pasted looks like the result of double-encoding the names in 
 UTF8. For instance, the first two characters:

 ا

 are codepoints U+D8 and U+A7. Together, those two bytes (read as UTF8) 
 make up the single character U+0627 (ARABIC LETTER ALEF) which is what I 
 suspect is the intended value.

 --Matt Jones



-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/eb0e044e-f9ca-47da-858b-fddc72e9b125%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: SSH/VNC/RDP Client Gems

2015-08-24 Thread Matt Jones


On Saturday, 22 August 2015 02:51:44 UTC-4, Reg Natarajan wrote:

 I have a new project that I'm considering writing in Rails.  I've never 
 written anything in Rails but I've been through my share of languages over 
 the last few decades and I'm not afraid of new things.  Given this, I may 
 have some concepts wrong and will almost certainly have some wording wrong.

 I need an SSH client library that will run in a browser and which doesn't 
 use Java or Flash.  Ideally raw HTML5.   It's essential that it support 
 both password and key based authentication.  It would be nice to have but 
 not essential that I could also have VNC and even RDP.   I'm assuming I'm 
 looking for a Rails Gem. 


Without Java or Flash, running in a browser is not exactly possible. 
There are solutions like (haven't tried this, was a top Google result):

https://github.com/liftoff/GateOne/

but that isn't an SSH client in a browser, it's a browser-based interface 
to the SSH client on the server. Using it with key-based authentication 
means the private keys will need to be available to the *server*, which may 
be a deal-breaker if you're trying to build a service for people to connect 
to third-party SSH hosts.

There are similar projects for RDP:

http://guac-dev.org/

But again, this is a JS frontend to server-installed software approach, 
not entirely client-side.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/a98b509a-592a-4653-b322-3c01f1963f51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Arabic text showing not properly in the file of s3

2015-08-21 Thread Matt Jones


On Thursday, 20 August 2015 06:03:13 UTC-5, amtest wrote:

 I have uploaded the csv to s3 with rails, but the issue is, that the file 
 have arabic names, so when i open that csv file directly from s3 console, 
 its showing the arabic names as gibberish, i have attached that *image* 
 here



 https://lh3.googleusercontent.com/-7MUHzpfGKls/VdWzcCb2WkI/AY8/k_hYB0rIqrw/s1600/Screen%2BShot%2B2015-08-20%2Bat%2B2.16.55%2BPM.png

 also i tried to add that charset utf, but its showing as same, is there 
 any workaround for this? 

 url = object.url_for(:read, {expires: E::EXPIRE,
  :content_type = text/csv;charset=utf-8, 
 response_content_disposition: attachment;filename=#{filename[0]}.csv }).to_s


You may need to verify the data is not already corrupted in the CSV. The 
text you've pasted looks like the result of double-encoding the names in 
UTF8. For instance, the first two characters:

ا

are codepoints U+D8 and U+A7. Together, those two bytes (read as UTF8) make 
up the single character U+0627 (ARABIC LETTER ALEF) which is what I suspect 
is the intended value.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/f6f539e0-4d93-4332-9d53-ea58114992ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: how to find what all associations have dependent: destroy associated with them from a concern

2015-08-20 Thread Matt Jones


On Saturday, 18 July 2015 01:56:43 UTC-5, Aravind Gopalakrishnan wrote:

 I am building a soft delete solution a la 
 https://github.com/discourse/discourse/blob/master/app/models/concerns/trashable.rb
  
 . Right now I am manually finding which all associated models need to be 
 deleted when a model is deleted and doing it manually in each model which 
 of course is a not a good practice. How do I do it? I don't want to use a 
 gem, I want to write logic in my own hands.


The place to start is `reflect_on_all_associations`:

http://api.rubyonrails.org/classes/ActiveRecord/Reflection/ClassMethods.html#method-i-reflect_on_all_associations
 

This will give you all the associations defined for the model. You can then 
request the option you're interested in thus:
```
klass.reflect_on_all_associations do |reflection|
  if reflection.options[:dependent]
# do something with it
  end
end
```

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/06155404-5fc0-4a86-92b2-9416a280b7d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Why does rake behave differently in production

2015-08-20 Thread Matt Jones


On Friday, 7 August 2015 15:38:17 UTC-5, Tyler DeWitt wrote:

 Hello,

 I use RabbitMQ to transfer information from one component to another 
 within my system. I have written a rake task which sets up the RabbitMQ 
 client (the Bunny gem), then sets up a blocking listener so that I can 
 process incoming messages.  When I run this rake task, I use the 
 :environment task to load the rails app (the rake task relies on several 
 models and service objects). 

 When I deployed my system to production, I noticed that my Rabbit task was 
 not working as expected. Digging into the log, I found that the service 
 objects and models were not being loaded by rake. This was strange, since I 
 called :environment.  Looking further into it, I've been informed that this 
 is the expected behavior, that rake does not preload the rails environment 
 in production.

 I'm guessing I'm doing something wrong. Should I not be using rake to set 
 up these listeners? If rake is acceptable, is there a way to test the load 
 path so I see these errors before production?  Is :environment only 
 designed to be used in development?


:environment should work everywhere - I've been using it in production rake 
tasks for years. Can you be more specific about how the task was not 
working as expected? If it failed to start, what was the error message? 
Try running it with `--trace` to capture the stack trace when it fails.

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/f7ecb2ee-9fa5-45c1-a486-69db67c9ba26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: I am new to Rails and Cucumber. Can someone help me with the error below?

2015-08-20 Thread Matt Jones


On Thursday, 20 August 2015 12:42:58 UTC-5, ishaque mohammed wrote:

 I am on windows 7, ruby 2.2.2p95, rails 4.2.3.



 C:\sites\gmailrails generate cucumber

 C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.10-x64-mingw32/lib/sqlite3.rb
 :6:in `require': cannot load such file -- sqlite3/sqlite3_native 
 (LoadError)


The sqlite3 gem also requires a native SQLite3 driver to be installed. See 
this post for possible solutions:

http://stackoverflow.com/questions/15480381/how-do-i-install-sqlite3-for-ruby-on-windows

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/c283d353-6aa0-4ffc-98d6-35f1cae17462%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Downgrading from Ruby 2.1.6 to Ruby 1.8.7

2015-08-20 Thread Matt Jones


On Wednesday, 19 August 2015 23:22:14 UTC-5, Ruby-Forum.com User wrote:

 Hi All, 

 Our client wants to downgrade our e-commerce website from Ruby 2.1.6 to 
 Ruby 1.8.7. I know this makes no sense. But when we got the requirement 
 to do the website, we developed using the latest version 2.1.6 but the 
 client wants to have the website in the old version, since his server is 
 not compatible with new one (MAKES SENSE?, but no other way). 


Ruby will compile on fairly near anything with a sensible C compiler and 
the `configure` program. If the server is so outdated that it doesn't have 
that, there are other problems.

There are a variety of tools for allowing multiple Ruby versions to coexist 
on one system; you should strongly suggest using one.

1.8.7 was end-of-lifed (no further updates from the core team) in June 
2013. It received a followup set of security patches in December 2013 to 
address CVE-2013-4164, but those were from a team at Heroku. Unless you or 
your client's team have the capability to evaluate 1.8.7's vulnerability to 
the subsequent 18 months of reported vulnerabilities, you are taking a 
massive security risk.

Apart from security, the other big reason to encourage a Ruby upgrade vs. 
an application rewrite is that the Ruby upgrade is straightforward - even 
if the server is particularly badly-configured, it's still ultimately a 
well-documented process to get Ruby to build. Rewriting the application is 
much trickier.

If none of those arguments work, at least post the name of the company on 
here. I'd like to make sure I never give them my credit card number...

--Matt Jones

Could anyone help us? Is there any other tool to do the migration from
 2.1.6 to 1.8.7. ?? 

 Looking for help from you guys. Thanks in advance. 

 -- 
 Posted via http://www.ruby-forum.com/. 


-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/2cd9dca1-2ee3-49d5-b1b5-3a32cd19d3cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Upgrading from rails 3.0 to 3.2

2015-08-20 Thread Matt Jones


On Wednesday, 19 August 2015 20:20:59 UTC-5, Ruby-Forum.com User wrote:

 Hi, 
 I am new to ruby on rails development. Please excuse me if my question 
 is too obvious. I am trying to upgrade from rails 3.0 to 3.2. I am stuck 
 at a point. I am running into this following error. 

 INTERNAL ERROR!!! undefined method `abstract_class?' for 
 #Class:0x007f8692ac2450 
   
 /Users/CRalladoddi/.rvm/gems/ruby-1.9.3-p551/gems/attr_encrypted-1.2.1/lib/attr_encrypted.rb:241:in
  

 `method_missing' 
   
 /Users/CRalladoddi/.rvm/gems/ruby-1.9.3-p551/gems/activerecord-3.2.13/lib/active_record/dynamic_matchers.rb:55:in
  

 `method_missing' 
   
 /Users/CRalladoddi/.rvm/gems/ruby-1.9.3-p551/gems/attr_encrypted-1.2.1/lib/attr_encrypted/adapters/active_record.rb:50:in
  

 `method_missing_with_attr_encrypted' 
   
 /Users/CRalladoddi/.rvm/gems/ruby-1.9.3-p551/gems/activerecord-3.2.13/lib/active_record/base.rb:421:in
  

 `inspect' 

 What I found is that, the method 'abstract_class?' has been moved from 
 base.rb to inheritance.rb in rails 3.2. 
 I was actually trying to use execute the following statement when this 
 error happened. 
 ActiveRecord::Base.connection.column_exists? klass.table_name, :user_id 

 Any ideas on work arounds 


That version of attr_encrypted is fairly old, but I don't think it's the 
culprit. Can you post the full stack trace?

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/92a33111-fdf5-4f79-920c-48815585af4e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Restclient error

2015-08-05 Thread Matt Jones


On Wednesday, 5 August 2015 01:36:35 UTC-4, venkata sai Reddy wrote:

 caught RestClient::SSLCertificateNotVerified: SSL_connect returned=1 
 errno=0 state=SSLv3 read server certificate B: certificate verify failed: 


Take a look at http://mislav.uniqpath.com/2013/07/ruby-openssl/ which will 
walk through how to troubleshoot this.

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/5042273c-e967-48e8-9d68-0ffe10eadcd2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Helps us with your feedback

2015-08-05 Thread Matt Jones


On Wednesday, 5 August 2015 06:50:50 UTC-4, tomcoo...@gmail.com wrote:

 Hey there

 We are dev team building outsource projects. And each time finishing the 
 projects we've had a pain with configuring backups (files and DBs) for our 
 customer's VPS. 

 Honestly, I think that you, guys, Ruby on Rails developers, face the same 
 issue every single day. So while solving this problem, we've built the 
 BitCalm.com https://bitcalm.com service.

 Please check it out and give us your feedback.
 Do you think it's useful for anybody else but us or is it creepy shit? =)

 If you're interested, here are core features:
 - It helps to configure auto backups to S3 in 1 minute.
 - incremental backups for your files and dump backups for your DBs.
 - web-dashboard to add/configure/manage multiple backups in a single place.


Quick thoughts:

* the option to install via a remote ROOT LOGIN concerns me. Having root 
*able* to log in over SSH is a security antipattern. Having SSH with 
passwords enabled is one too. Giving the server's root password to a third 
party is an even bigger mess.

* the encryption situation is not explained well. In particular, it is 
unclear how exactly data is encrypted during transmission and who holds the 
keys used for that. It also appears that some features are 
yet-to-be-implemented, as mentioned in the Security FAQ: In 2015 we plan 
to enable data encryption before sending with your own public key. This is 
of concern especially for customers using BitCalm-provided S3 storage, 
since the website can download the backup to the user's local storage - and 
therefore (absent a layer of encryption) read the contents.

* there's a pair of mutually-exclusive statements in the Technical FAQ, in 
adjacent paragraphs:

The size of database data should not exceed free space in your /tmp 
folder.

Databases of any size may be backed up, because all reading and 
compression process is done with chunks of data in RAM.

One or the other of these is presumably false.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/4ad1a54e-89ef-4598-9230-c620f780087c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: How to preserve the session id whether the http request header contains 'Pragma'='no-cache'.

2015-08-05 Thread Matt Jones


On Tuesday, 4 August 2015 01:41:18 UTC-4, Hiroto Mukouhara wrote:

 The new session id is created when the http request header contains
 'Pragma'='no-cache' on our RoR environment. Our goal is that the session
 id is preserved if the http request header contains 'Pragma'='no-cache'.
 Please let us know how to preserve the session id.

 The detailed sequence is shown below:

 1. The user downloads the Microsoft World file from RoR application, and
opens that file using 'Protected View'.

 2. The user clicks the url link which is written in that Word file. The
clicked url link points to a page which is located on that RoR
application.

 3. On opening that url link, the http request header contains
'Pragma'='no-cache', and the new session id is created with the http
response header which contains 'Set-Cookie'. 

 If the user opens that file not using 'Protected View' on the sequence 1,
 the session id is preserved on the sequence 3. The http request header
 doesn't contain 'Pragma'='no-cache'.


I can't find much documentation for Protected View, but there's some 
indication that it may be fiddling with the context that the web request 
uses when you click on the link:

https://onmessages.wordpress.com/2015/01/19/a-security-problem-has-occurred-in-word/

This may be a security restriction to prevent malicious documents from 
including hyperlinks to third-party sites that rely on the user's existing 
cookies to do XSS.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/b1144751-fc88-4495-a8fe-4431c575841d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: How to save double-byte characters in mongodb?

2015-07-19 Thread Matt Jones


On Thursday, 9 July 2015 04:47:00 UTC-4, Kiran Kumar wrote:

 I have a Model called *Review.rb*

 class MovieNews::Review
 include Mongoid::Document
 include Mongoid::Timestamps
 include Mongoid::Userstamp
 include Mongoid::Search

 field :story,   type: Stringend


 When i create a instance of class review and tried saving which local 
 language telugu in the field, im getting wrong output.

 Ex1:

 review = MovieNews::Review.new
 review.story = నటవర్గం after pasting here it's spelling goes worng నటవర్..
 review.save = true

 Does Mongodb supports local languages to create collection? Someone please 
 help me out.

 As Fred has indicated, is the issue that the string appears incorrectly in 
the terminal / editor, or that it is saved incorrectly to the database? I 
was able to produce a string that looks (to my 
thoroughly-unfamiliar-with-Telegu-script eyes) like your spelling goes 
wrong example by replacing the last six bytes of the string with two 
literal periods (codepoint U+2E).

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/f9c5665f-c59d-488a-8e67-2582520fbd8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Re: Re: Re: Re: Re: Re: Migrating a complete Ruby rails app off heroku!

2015-07-09 Thread Matt Jones


On Monday, 6 July 2015 12:21:53 UTC-4, Ruby-Forum.com User wrote:

  No. There is no substitute for understanding Ruby and Rails enough 
  to work through whatever is going on. Without a certain baseline level 
  of knowledge you're just spinning your wheels, as shown above. 
  
  Sorry. 
  

 Y'know Hassan, 

 I've worked with computers and IT for as long as I can remember - and 
 that's a long time. Mostly with Windows (of late) and had my fair share 
 of other OSs too - from DOS  Unix to Linux But it's at times like 
 these that I know why I really prefer M$ Products... 

 If it was some noob asking me the same questions, I'd have been able to 
 point her/him to something lke this -- 
 https://www.youtube.com/watch?v=GPK9MGjhbhI and hope for the best. And 
 they probably would have stumbled around and found their way. Maybe even 
 been able to get it up and running :-) 

 You kinda guys with your cryptic answers is what makes it all the more 
 difficult. Obviously I'm looking for some silver bullet. And there is I 
 know. Not been around so long that everything's gotta be done the hard 
 way see. So anyways 


There is a silver bullet. LEARN HOW TO USE THE THING, OR HIRE SOMEBODY WHO 
KNOWS WHAT THEY ARE DOING. Expecting people to help you when you don't 
understand what you're fiddling with is like standing beside your car with 
a flat tire and demanding a silver bullet to make up for your lack of a 
wrench and a jack.

 

 Thanx for the help. Your confidence in the ability of others to figure 
 out stuff they don't yet know is applaudable. I'm headed off this forum. 
 Back to where I can figure it out with people that don't need to make 
 every set-up into a trial by fire - rite of passage... Thanx. 

 And Colin, sincere thanks you did try. But maybe in future - if you 
 thought more like M$, it'd make the world a better place. There is a 
 quick and fast (and yes dirty) way to get stuff going. Not everything's 
 gotta be perfect and As it should be see...


BTW, I've got a Windows 1.0 app that I need to recompile for Windows 10. I 
need you to tell me the silver bullet to make all the compilation errors 
go away. It doesn't need to be as it should be, but a way SURELY exists, 
right? 

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/17b387fe-7cea-4214-99c1-71733bf5a11c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: NoMethodError (undefined method `sismember' for nil:NilClass)…Trying to deploy on heroku

2015-05-28 Thread Matt Jones


On Sunday, 17 May 2015 15:08:07 UTC-4, Ruby-Forum.com User wrote:

 I get the following error: 

 2015-05-17T17:25:40.349230+00:00 app[web.1]: Started GET /movies/1 for 
 160.9.0.153 at 2015-05-17 17:25:40 + 
 2015-05-17T17:25:40.423697+00:00 app[web.1]: Completed 500 Internal 
 Server Error in 67ms 
 2015-05-17T17:25:40.355931+00:00 app[web.1]: Processing by 
 MoviesController#show as HTML 
 2015-05-17T17:25:40.425095+00:00 app[web.1]: 
 2015-05-17T17:25:40.406984+00:00 app[web.1]:   Movie Load (2.4ms) 
 SELECT  movies.* FROM movies WHERE movies.id = $1 LIMIT 1 
 [[id, 1]] 
 2015-05-17T17:25:40.425098+00:00 app[web.1]: NoMethodError (undefined 
 method `sismember' for nil:NilClass): 
 2015-05-17T17:25:40.425100+00:00 app[web.1]:   app/models/movie.rb:20:in 
 `cart_action' 
 2015-05-17T17:25:40.425102+00:00 app[web.1]: 
 2015-05-17T17:25:40.425101+00:00 app[web.1]: 
 app/controllers/movies_controller.rb:9:in `show' 
 2015-05-17T17:25:40.425104+00:00 app[web.1]: 
 2015-05-17T17:25:41.951208+00:00 heroku[router]: at=info method=GET 
 path=/movies/4 host=hidden-savannah-5835.herokuapp.com 
 request_id=cbb36b63-06ee-4da0-992d-6d512d431ea4 fwd=160.9.0.153 
 dyno=web.1 connect=0ms service=17ms status=500 bytes=1714 
 2015-05-17T17:25:41.932183+00:00 app[web.1]: Started GET /movies/4 for 
 160.9.0.153 at 2015-05-17 17:25:41 + 
 2015-05-17T17:25:41.941428+00:00 app[web.1]: Completed 500 Internal 
 Server Error in 5ms 
 2015-05-17T17:25:41.935883+00:00 app[web.1]: Processing by 
 MoviesController#show as HTML 
 2015-05-17T17:25:41.935891+00:00 app[web.1]:   Parameters: {id=4} 
 2015-05-17T17:25:41.939396+00:00 app[web.1]:   Movie Load (2.2ms) 
 SELECT  movies.* FROM movies WHERE movies.id = $1 LIMIT 1 
 [[id, 4]] 
 2015-05-17T17:25:41.944520+00:00 app[web.1]: 
 2015-05-17T17:25:41.944523+00:00 app[web.1]: NoMethodError (undefined 
 method `sismember' for nil:NilClass): 
 2015-05-17T17:25:41.944525+00:00 app[web.1]:   app/models/movie.rb:20:in 
 `cart_action' 
 2015-05-17T17:25:41.944526+00:00 app[web.1]: 
 app/controllers/movies_controller.rb:9:in `show' 
 2015-05-17T17:25:41.944528+00:00 app[web.1]: 
 2015-05-17T17:25:41.944529+00:00 app[web.1]: 

 movie.rb (model) 

 class Movie  ActiveRecord::Base 
   has_many :purchases 
   has_many :buyers, through: :purchases 

   before_save :embed_video_url 

   def poster 
 http://ia.media-imdb.com/images/M/#{poster_url}; 
   end 

   def imdb 
 http://www.imdb.com/title/#{imdb_id}/; 
   end 

   def embed_video_url 
 self.video_url = 
 //www.youtube.com/embed/#{video_url.split('v=')[1].split('list')[0]} 
 http://www.youtube.com/embed/#%7Bvideo_url.split('v=')[1].split('list')[0]%7D
  

   end 

   def cart_action(current_user_id) 
 if $redis.sismember cart#{current_user_id}, id 
   Remove from 
 else 
   Add to 
 end 
   end 
 end 

 movies_controller.rb 

 class MoviesController  ApplicationController 

   def index 
 @movies = Movie.all 
   end 

   def show 
 @movie = Movie.find(params[:id]) 
 @cart_action = @movie.cart_action current_user.try :id 
   end 

 end 

 The weird about this error is that the application run without any 
 problem locally but when I deployed to heroku I can see the first page 
 but when I click to a movie or trying to log in i get error. 

 Any help? 


You did not include the code that sets $redis, and I suspect that's where 
the problem is. Connecting to Redis on Heroku may be slightly different 
that local, since dynos are not guaranteed to continue existing between 
requests.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/dfbb0bac-1a99-4e17-ac1e-dd7743cb2243%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: why rails new xx failed on win7 x64?

2015-05-28 Thread Matt Jones


On Friday, 8 May 2015 10:25:55 UTC-4, mnz hz wrote:

 rails new xxx

 ...

 Using jbuilder 2.2.13

 *Gem::RemoteFetcher::FetchError: Errno::ECONNABORTED: An established 
 connection was aborted by the software in your host machine. - SSL_connect*
  (https://rubygems.org/gems/jquery-rails-4.0.3.gem
 )
 An error occurred while installing jquery-rails (4.0.3), and Bundler cannot
 continue.
 Make sure that gem install jquery-rails -v '4.0.3' succeeds before 
 bundling.



Hard to say for sure, but you may want to try these troubleshooting steps:

https://gist.github.com/luislavena/f064211759ee0f806c88 

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/282bfc07-230f-45de-8ebc-927ffc4db82b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: tinyint(1) and boolean

2015-05-21 Thread Matt Jones


On Sunday, 10 January 2010 14:57:15 UTC-5, Matt Jones wrote:

 On Jan 9, 6:16 pm, codeinnova sumangur...@gmail.com wrote:
  So i had a boolean attribute in my model which gets interpreted to
  tinyint(1) in mysql by rails migrations. Now tinyint(1) accepts a
  range in mysql and i want to change my boolean attribute to an
  attribute which can accept 3 values(0,1,2).
  I made the change to the view and when i post the form selecting the
  selecting the value '2', it still gets saved as a '0'. I checked the
  params when the post is done and the value of the form element was '0'
  even though i selected '2'(I am using a dropdown list here).
  So my question really is, how can i make rails to accept more values
  without changing the type to something other than tinyint(1)? And why
  this weirdness?

 As others have pointed out, MySQL doesn't have a straight boolean
 field type, so the tinyint(1) hack is used instead.

 You'll either need to turn off emulate_booleans (which may break other
 stuff) or just change the column type, as the MySQL adapter will
 detect the current type as :boolean and the AR-generated accessors
 will wind up casting values as booleans automatically...

 
Updating this old post, because there's now a way to handle situations 
where you've got a `tinyint(1)` column that has non-0/1 values in it.

The relevant documentation is 
here: 
https://github.com/rails/rails/blob/daffea59db118fce4247d335eabea026cc54d7bc/activerecord/lib/active_record/attributes.rb#L17

Note that in 4.2.1 the entire module is #:nodoc:, but it has been made 
public in master.

To use it, you redeclare a column that would otherwise be misdetected. 
Example:

  class SomeModel  ActiveRecord::Base
attribute :a_tinyint_1_column_that_isnt_a_boolean, Type::Integer.new
  end

Passing an instance of `ActiveRecord::Type::Integer` means the column will 
not have the boolean typecasting behavior anymore.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/e52b40ef-b6c0-4bcc-9142-8ad4383a3382%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Can I use different version of action mailer

2015-05-15 Thread Matt Jones


On Thursday, 14 May 2015 14:37:53 UTC-4, Ruby-Forum.com User wrote:

 Hello!  I've been trying to upgrade from Ruby 1.8.6 to ruby 2.2.2 at my 
 workplace, and as expected its been a bit rough.  :) 

 I have a old 2.0.5 rails application that needs to keep working,  and 
 I've ran into a bit of a roadblock with the ActionMailer having a syntax 
 error.  However the problem is fixed in the 2.3.18 version of the gem. 

 Is it possible to tell rails 2.0.5 to use the 2.3.18 gem for action 
 mailer only?  I haven't been able to find anything about using different 
 versions of the gems so I'm suspecting not, but it would be great to 
 know how.  :) 


The odds aren't great that such a thing would work; the internals were 
moving around a lot between versions back then.

Unrelated: you may have already done this, but make SURE you've patched the 
JSON parser to close these holes:

CVE-2013-0156: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2013-0156 
CVE-2013-0333: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2013-0333

I doubt these are the only security vulnerabilities in 2.0.5, but these two 
are some of the nastiest.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/9fd7bb8d-d158-4746-aa26-4f38efde1393%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: action mailer settings and dkim signing

2015-02-18 Thread Matt Jones


On Saturday, 14 February 2015 21:17:21 UTC-5, Stephen Burke wrote:

 I am trying to figure out why this block of code in my 
 environments/production.rb file is causing the dkim signing to break.  I 
 have email being sent from a rake task with my UserMailer class.  It is 
 derived from Devise::Mailer.  If I have the action_mailer configuration 
 block within the config.after_initialize the dkim signature does not go 
 through.  If I don't have that line after_initialize the signature goes 
 through.  Can someone shed some light on this for me?

 Here's the code for my UserMailer class and the production.rb file. 

 user_mailer.rb

 require #{Rails.root}/app/helpers/user_helper
 include UserHelper

 class UserMailer  Devise::Mailer
   helper :application # gives access to all helpers defined within 
 `application_helper`.
   include Devise::Controllers::UrlHelpers # Optional. eg. 
 `confirmation_url`
   default from: Save The Sparkles con...@savethesparkles.com 
 javascript:,
   reply_to: con...@savethesparkles.com javascript:
   ...
 end


 environments/production.rb 

 config.action_mailer.asset_host = 'http://savethesparkles.com'

 config.action_mailer.default_url_options = { host: 'savethesparkles.com' }
 config.after_initialize do
   config.action_mailer.perform_deliveries = true
   config.action_mailer.raise_delivery_errors = true
   config.action_mailer.delivery_method = :smtp
   config.action_mailer.smtp_settings = {
 address:  'email-smtp.us-east-1.amazonaws.com',
 port: 587,
 domain:   'savethesparkles.com',
 user_name:ENV['AWS_SES_USER'],
 password: ENV['AWS_SES_PASS'],
 authentication:   :login,
 enable_starttls_auto: true
   }
 end


The documentation for Rails::Railtie::Configuration describes 
after_initialize as the last configurable block to run, called after 
frameworks initialize. ActionMailer's own initialization routine copies 
the values from config.action_mailer *before* the code above sets them. So 
the behavior you've described makes sense.

A better question is, why is having after_initialize here important? What's 
the intent?

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/cd54be92-1652-4b2b-9199-8371a70c8581%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: How to use custom Ruby on Rails Engine helpers inside the Main App

2015-02-11 Thread Matt Lee
it's not bad

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/1e745c3bb9a45ecea7c013094cfe5f7a%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] OpenStruct Rails

2015-02-09 Thread Matt B.
Hey guys,

I am new to Rails, and have just completed my first app, a simple
Blog... However I am looking to add more to it, I had a parser created
for me that will scrape sports lines off a webpage. The problem is it is
stored in an OpenStruct and I am not sure how to store it. He file runs
just fine and I even placed it in my controller with the Puts
Results[]  is a specific game code and it works perfect.

However I want to store these values in a Database and then every time
the webpage is refreshed it checks the lines and if they changed
overwrites it.

The name of my OpenStruct object is results and I can do a for each pair
puts k v or I can do a specific gamecode which is unique. And cal like
about results[x] .

I believe the script we be its own controller but how and where do I
store the values ??? Please help.  Below is the Gists with the parse
code if that helps.

https://gist.github.com/weaksauce/3b9cd8497c644fa33ddb


Matt

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/64e3af38190c696a27c35c7f8b576ec9%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: people are yelling, why?

2015-02-05 Thread Matt Jones


On Wednesday, 4 February 2015 14:36:40 UTC-5, Ruby-Forum.com User wrote:

 I'm new to learning how to think, and programming, actually. While I 
 don't mind being thrown to the wolves, I have no idea how to fix the 
 issue I'm struggling with, which is the following: 
 I currently have a table where two tabs, one, incomplete, and two, 
 complete have pagination tabs at the bottom of the table. the document 
 model reads self.per_page = 10, which represents the number of documents 
 before moving onto the next page. currently, I've made 10 documents, and 
 can move between pages smoothly. however, when on the complete tab, and 
 while there is only one entry when clicking for the next page, I'm being 
 redirected to the incomplete tab, and i don't want that. 

 some helpful dude, though didn't work was like 

 @post = Post.paginate(:page = params[:page]) #controller 
 = will_paginate @post, renderer: BootstrapPagination::Rails #view 

 where post is changed out with document. 

 so what i did in the document_controller.rb file was definded a method 
 index and ended the method. when defining the method, I put @document = 
 Document.paginate(:page = params[:page]) and the shit just broke. 


The hardest error to debug remotely is shit just broke. What happened? 
What error message do you get when you access that route through the 
browser? 

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/fc1f9025-47a1-4145-a8f9-ce649cc63ba0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Full Time Job :: Sr. Ruby On Rails Developer (San Francisco, Oakland)

2015-01-19 Thread Matt Jones


On Thursday, 15 January 2015 17:43:21 UTC-5, manan.g...@gmail.com wrote:

 Please go through the below requirement and if interested, please share 
 your updated resume.


 *Designation: Sr. Ruby Developer Location: San Francisco , Oakland 
 (California)* 

*Salary : $100k- $150k + benefits*

Not to tell you how to do your job, but that salary range would be 
borderline when recruiting a senior dev here in the Midwest - and probably 
gets more lolz than responses in the Bay...

--Matt Jones
 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/b69805b7-16f3-4cf3-a74c-cbd666b80b96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Need opinions on a Rails app as a framework

2015-01-19 Thread Matt Jones


On Friday, 16 January 2015 00:01:26 UTC-5, Chason Choate wrote:

 I have an interesting use case for Rails and I would greatly appreciate 
 this community's opinion on the matter. 
 I'm curious if it's possible to build a Rails app that can accomplish the 
 following:

 Environment stipulations
 -

 * Must run on the JVM so JRuby.
 * The app will not have internet access in production. (We still have 
 build servers that can package gems)

 Ideal functionality
 -
  
 * The main Rails app should be able to support a variable amount of 
 engines.
 * I have played with this and it can be done by tweaking the Gemfile 
 to load the engines.
 * Downside is we now have to disregard the Gemfile.lock to accommodate 
 additional engines being added at any time.
 * Engines should be drop-in ready.
 * The engines should come packaged with all the gems they need to run.
 * There should be no additional installing steps after dropping in an 
 engine.
 * That means no 'bundle install' or anything else.

 So my major concern at the moment is with the gems. When I drop in an 
 engine and restart the server is there a way bundler can pick up the 
 packaged gems within the engine without any install step? Maybe playing 
 with the GEM_PATH or something? Anyway I would like to hear your opinions 
 and see if we can figure something out. Thanks for checking this out!


I think you're going to wind up fighting pretty hard against Bundler to do 
this. One good place to start is likely the Warbler community, as they've 
got experience deploying applications in a self-contained method as you've 
described.

I'd also recommend pushing back on the absolutely no install requirement; 
what's the motivation? It seems to me like there's not much space between 
users can write files on the web server and restart it and users who can 
run a command...

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/505cd0b5-eab6-4f5a-adbd-7dbf4a91503c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Link To New Association

2015-01-14 Thread Matt Jones


On Tuesday, 13 January 2015 11:22:14 UTC-5, Diego Dillenburg Bueno wrote:

 Further updates on my question above:

 what if I have a helper method to store the current_patient, having 
 always the last patient from my search query and on my 
 hospitalizations_controller I build the Create method something like this: 
 @hospitalization = 
 current_patient.hospitalizations.new(hospitalization_params) ? Would this 
 be the best way to work around this?


This is a great use case for nested resource routing - you aren't just 
trying to make *a* hospitalization, you're trying to make one for a 
particular patient. So instead of a route like:

/hospitalizations/new

you'd want to use:

/patients/:patient_id/hospitalizations/new

One way to read this is make a new hospitalization for the patient 
:patient_id.

To do this in the routes file, you'd have something like:

resources :patients do
  resources :hospitalizations
end

You can make a link to the new page with something like (in an ERB 
template):

link_to New Hospitalization, new_patient_hospitalization_path(@patient)

assuming you've got the desired patient record in @patient.

--Matt Jones
 


 2015-01-13 10:50 GMT-02:00 Diego Dillenburg Bueno diegodi...@gmail.com 
 javascript::

 Hey there,

 I have a patients model which has many hospitalizations, from the 
 patients#show I want to generate a link to hospitalizations#new creating a 
 new association to this very same patient, any ideas on how to do that? I 
 want it to when I get to the hospitalizations#ne I be able to manipulate 
 the output the patient data in the generated view and submit a 
 Patient.hospitalizations.create, how would be the best approach for that?

 Thanks in advance,

 Diego Dillenburg Bueno
 Graduando em Ciências da Computação
 UNESP - Rio Claro
 (12) 98116-7741
 https://www.facebook.com/diegodillenburg 
 http://br.linkedin.com/in/diegodillenburg 
 https://github.com/diegodillenburg

  


-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/3b5be9c1-6efc-4920-85d6-9a89c52a008f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Ruby code Injectors: Closures as Modules: Jackbox

2015-01-01 Thread Matt Jones


On Monday, 29 December 2014 14:45:19 UTC-5, Ruby-Forum.com User wrote:

 ANNOUNCING a new release of Jackbox. 

 Jackbox toys with the ideas of closures as modules.  In it you'll find a 
 series of new takes on ruby that are sure to spike you interest.  With 
 it we have come up with a solution to the decorators handicap in ruby 
 and introduced some new constructs for code injection. 

 Please feel free to use it free of charge and to send us your comments 
 or inquiries.  Available from RubyGems.org for Linux, Mac, and Windows. 
 Just run: gem install jackbox. 

 More info here: https://github.com/LouHenryAlvarez/jackbox 
 https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2FLouHenryAlvarez%2Fjackboxsa=Dsntz=1usg=AFQjCNEIJkJHncKVgUKOmn0y7pAkbzIaoQ
  


 CHANGES: Made ffi a dependency instead of part of the gem.  Added some 
 additional specs.  In particular, added specs for the #with construct 
 and the #lets construct for the disbelievers.  To execute all the specs: 
 you need to be inside the gem directory where ever this maybe on your 
 system and run rspec from the gem directory itself. 


 Thank you. 


 IMPORTANT NOTICE: If you feel the need to decompile the code even though 
 WHAT is contained in it is not worth the trouble you are hereby formally 
 instructed to: Cease and Desist.  Jackbox and the code in it are 
 copyrighted.  If you encounter bugs, you don't need to debug them.  We 
 will debug them for you.  Just send us your stack trace and an 
 explanation of the problem to the address on the GitHub page or on the 
 gem itself.  We will do our most to provide you with outstanding 
 customer service. 


 Bullshit. So far, your customer service has included shipping a gem that 
couldn't even LOAD SUCCESSFULLY. Take your spam to some other group.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/16beece5-0e53-4a36-8ccb-e04c0c28ca13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: An error occurred while installing ruby-oci8 (2.1.7)

2015-01-01 Thread Matt Jones


On Monday, 29 December 2014 15:26:55 UTC-5, Ruby-Forum.com User wrote:

 Hi , 

 I am getting into the below error while running bundle from bamboo 
 server. 



 Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native 
 extension. 
 build  29-Dec-2014 15:13:05 
 build  29-Dec-2014 15:13:05  /usr/local/bin/ruby extconf.rb 
 build  29-Dec-2014 15:13:05  checking for load library path... 
 build  29-Dec-2014 15:13:05LD_LIBRARY_PATH... 
 build  29-Dec-2014 15:13:05  checking 
 /usr/java/jdk1.6.0_30/jre/lib/amd64/server... no 
 build  29-Dec-2014 15:13:05  checking 
 /usr/java/jdk1.6.0_30/jre/lib/amd64... no 
 build  29-Dec-2014 15:13:05  checking 
 /usr/java/jdk1.6.0_30/jre/../lib/amd64... no 
 build  29-Dec-2014 15:13:05checking ld.so.conf... no 
 build  29-Dec-2014 15:13:05  checking for cc... ok 
 build  29-Dec-2014 15:13:05  checking for gcc... yes 
 build  29-Dec-2014 15:13:05  checking for LP64... yes 
 build  29-Dec-2014 15:13:05  checking for sys/types.h... yes 
 build  29-Dec-2014 15:13:05  checking for ruby header... ok 
 build  29-Dec-2014 15:13:05  *** extconf.rb failed *** 
 build  29-Dec-2014 15:13:05  Could not create Makefile due to some 
 reason, probably lack of necessary 
 build  29-Dec-2014 15:13:05  libraries and/or headers.  Check the 
 mkmf.log file for more details.  You may 
 build  29-Dec-2014 15:13:05  need configuration options. 
 build  29-Dec-2014 15:13:05 
 build  29-Dec-2014 15:13:05  Provided configuration options: 
 build  29-Dec-2014 15:13:05--with-opt-dir 
 build  29-Dec-2014 15:13:05--without-opt-dir 
 build  29-Dec-2014 15:13:05--with-opt-include 
 build  29-Dec-2014 15:13:05--without-opt-include=${opt-dir}/include 
 build  29-Dec-2014 15:13:05--with-opt-lib 
 build  29-Dec-2014 15:13:05--without-opt-lib=${opt-dir}/lib 
 build  29-Dec-2014 15:13:05--with-make-prog 
 build  29-Dec-2014 15:13:05--without-make-prog 
 build  29-Dec-2014 15:13:05--srcdir=. 
 build  29-Dec-2014 15:13:05--curdir 
 build  29-Dec-2014 15:13:05--ruby=/usr/local/bin/ruby 
 build  29-Dec-2014 15:13:05--with-instant-client 
 build  29-Dec-2014 15:13:05--without-instant-client 
 build  29-Dec-2014 15:13:05 
 /usr/local/lib/ruby/gems/2.0.0/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:891:in
  

 `get_home': RuntimeError (RuntimeError) 
 build  29-Dec-2014 15:13:05from 
 /usr/local/lib/ruby/gems/2.0.0/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:707:in
  

 `initialize' 
 build  29-Dec-2014 15:13:05from 
 /usr/local/lib/ruby/gems/2.0.0/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:320:in
  

 `new' 
 build  29-Dec-2014 15:13:05from 
 /usr/local/lib/ruby/gems/2.0.0/gems/ruby-oci8-2.1.7/ext/oci8/oraconf.rb:320:in
  

 `get' 
 build  29-Dec-2014 15:13:05from extconf.rb:18:in `main' 
 build  29-Dec-2014 15:13:05 
 --- 
 build  29-Dec-2014 15:13:05  Error Message: 
 build  29-Dec-2014 15:13:05Set the environment variable ORACLE_HOME 
 if Oracle Full Client. 
 build  29-Dec-2014 15:13:05Append the path of Oracle client 
 libraries to LD_LIBRARY_PATH if Oracle Instant Client. 


As the messages here indicate, you need to set either ORACLE_HOME or add 
the client libraries to LD_LIBRARY_PATH. 

If the bamboo server mentioned in your post is the Atlassian CI server, 
you may need to coordinate the installation of the Oracle libraries with 
the administrators of that server.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/ce6ffe8c-9f51-4b81-a3a5-e2a0af5eab30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Has anyone heard of this Ruby project?

2015-01-01 Thread Matt Jones


On Tuesday, 30 December 2014 15:49:09 UTC-5, Ruby-Forum.com User wrote:

 Well, I tried on my Unix box running Ruby 2.1.1 and 1.9.3 through RVM 
 and I woke on both platforms.  I also ran the specs provided with the 
 gem after I copied them to a woking folder and I got no errors.   But of 
 course we have to wonder, what is the nature of this project? 


Sock puppets gotta sock, yo.

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/84cfb8c6-0854-485e-9f2b-0937e58392c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Has anyone heard of this Ruby project?

2014-12-26 Thread Matt Jones


On Sunday, 21 December 2014 15:55:26 UTC-5, Star Light wrote:

 https://github.com/LouHenryAlvarez/jackbox

 If it's true. It sounds like some pretty wild stuff.  Anyone care to 
 comment about this?


Followup to my original comment: the Github page only has specs. Rubygems 
has a gem, but it's got binary components without source and obfuscated 
source (RubyEncoder). I certainly wouldn't load this code anyplace that 
wasn't heavily sandboxed. I have no evidence that it's malicious, but have 
the same amount that it *isn't*.

There's some interesting ideas in there, but nothing interesting enough 
that I'd want to bring un-debuggable, un-updatable mystery code in that 
also locks me to MRI.

The barrage of announcement posts across rails-talk, ruby, ruby-dev, and 
ruby-core certainly haven't helped make a positive impression.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/0a4702e8-3f76-496a-9c9f-97a878f61d89%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Has anyone heard of this Ruby project?

2014-12-26 Thread Matt Jones


On Friday, 26 December 2014 17:56:39 UTC-5, Matt Jones wrote:



 On Sunday, 21 December 2014 15:55:26 UTC-5, Star Light wrote:

 https://github.com/LouHenryAlvarez/jackbox

 If it's true. It sounds like some pretty wild stuff.  Anyone care to 
 comment about this?


 Followup to my original comment: the Github page only has specs. Rubygems 
 has a gem, but it's got binary components without source and obfuscated 
 source (RubyEncoder). I certainly wouldn't load this code anyplace that 
 wasn't heavily sandboxed. I have no evidence that it's malicious, but have 
 the same amount that it *isn't*.

 There's some interesting ideas in there, but nothing interesting enough 
 that I'd want to bring un-debuggable, un-updatable mystery code in that 
 also locks me to MRI.

 The barrage of announcement posts across rails-talk, ruby, ruby-dev, and 
 ruby-core certainly haven't helped make a positive impression.


A final addon: the thing doesn't even WORK. Brand-new Ruby install on a 
brand-new Vagrant VM:

vagrant@precise32:~$ irb
irb(main):001:0 require 'jackbox'
TypeError: can't create instance of singleton class
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/jackbox-0.9.3.1/lib/jackbox.rb:188:in
 
`new'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/jackbox-0.9.3.1/lib/jackbox.rb:188:in
 
`block (2 levels) in decorate'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/jackbox-0.9.3.1/lib/jackbox.rb:51:in
 
`suppress_warnings'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/jackbox-0.9.3.1/lib/jackbox.rb:179:in
 
`block in decorate'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/jackbox-0.9.3.1/lib/jackbox.rb:208:in
 
`[]'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/jackbox-0.9.3.1/lib/jackbox.rb:208:in
 
`decorate'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/jackbox-0.9.3.1/lib/jackbox/examples/dir.rb:18:in
 
`block in class:Dir'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/jackbox-0.9.3.1/lib/jackbox/examples/dir.rb:17:in
 
`class_eval'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/jackbox-0.9.3.1/lib/jackbox/examples/dir.rb:17:in
 
`class:Dir'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/jackbox-0.9.3.1/lib/jackbox/examples/dir.rb:15:in
 
`top (required)'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/jackbox-0.9.3.1/lib/jackbox.rb:404:in
 
`require_relative'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/jackbox-0.9.3.1/lib/jackbox.rb:404:in
 
`encoded'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/jackbox-0.9.3.1/lib/jackbox.rb:2:in
 
`RGLoader_load'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/jackbox-0.9.3.1/lib/jackbox.rb:2:in
 
`top (required)'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in
 
`require'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in
 
`rescue in require'
from 
/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:144:in
 
`require'
from (irb):1
from /home/vagrant/.rbenv/versions/2.1.5/bin/irb:11:in `main'
---
System info:

vagrant@precise32:~$ ruby -v
ruby 2.1.5p273 (2014-11-13 revision 48405) [i686-linux]

vagrant@precise32:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04 LTS
Release: 12.04
Codename: precise
-

I'd add that EVEN IF THIS WORKED, it would be terrible - it's loading the 
file from lib/jackbox/examples/dir.rb, which redefines - ahem, decorates 
- methods of the stdlib Dir class to have entirely different semantics. For 
instance, `Dir.new(some_path)` now writes to the filesystem...

Some of the rest, on further examination, feels like over-abstraction / 
sugaring. For instance, here's how `lets` is implemented:

def lets(sym = nil, block)
  if sym.class == Symbol
define_method(sym, block)
  else
sym ? sym : block
  end
rescue StandardError
  raise LetsError
end

(BTW: RubyEncoder just makes this harder, not impossible. Not even 
particularly difficult, once you get used to reading YARV bytecode. 
RubyVM::InstructionSequence.disasm FTW!)

Digging into this, the first example for `lets` is USELESS. `lets bar 
=-(arg){ arg * arg }` is actually parsed as `lets(bar = -(arg){ arg * arg 
})`. This works, but `lets` does exactly fuckall since the actual 
local-variable-setting part is a side-effect of its argument.

Other fun things, in no particular order:

* attempting an install on Ruby 1.9.3 fails, since the gem was built 
expecting `byebug` to be available but that gem requires Ruby 2.0.0. The 
gemspec appears to be *attempting* to deal with this by including a 
conditional on RUBY_VERSION, but that code runs at gem-build time

[Rails] Re: puts command prints nothing !!!

2014-12-22 Thread Matt Jones


On Sunday, 21 December 2014 08:05:09 UTC-5, Nour-Eldin Abd-allah wrote:

 hi guys

 when i use the puts command to print something in sublime, it says 
 finished in 0.1s without the value it should print

 i think its an easy thing but i tried many ideas until i came here


This can happen when using tools to run code directly from your editor; 
some of them don't show the output of the command. Try running your code 
directly from your platform's command line.

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/38090d99-1502-4e52-879f-d20d1f5371c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Has anyone heard of this Ruby project?

2014-12-22 Thread Matt Jones


On Sunday, 21 December 2014 15:55:26 UTC-5, Star Light wrote:

 https://github.com/LouHenryAlvarez/jackbox

 If it's true. It sounds like some pretty wild stuff.  Anyone care to 
 comment about this?


I'll comment that this is the second place I've run across this, which is 
pretty remarkable for a project that currently contains specs but no 
implementation. ALL ABOARD THE HYPE TRAIN

As to the functionality, an awful lot of what's proposed there sounds like 
things you could do more clearly using modules / concerns directly. Hard to 
say for sure without code.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/cb0e62de-0790-4bb6-897b-9c5de57c1591%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Slow json rendering

2014-12-16 Thread Matt Jones


On Monday, 15 December 2014 14:59:02 UTC-5, Ruby-Forum.com User wrote:

 Hi, 


 I have around 2000 objects to render. Unfortunately the view rendering 
 with jbuilder takes very long time, although the objects are small like 
 this: 


 center: {lat: 48.8130685274225, lon: 10.0405494495457} 
 lat: 48.8130685274225 
 lon: 10.0405494495457 
 n: Aalen/Hirtenteich 
 st: null 
 sy: null 


 The result query I pass to the view looks like this 
 @resorts   = Resort.where(:id = resort_ids).includes(:snow_reports) 

 A resort has many snow_reports. st and sy are fields from snow reports. 

 the view looks like this: 

json.array!(@resorts) do |resort| 
   json.cache!(resort_light_#{resort.id}) do 

 #json.partial! 'json_partials/snow_in_resort', resort: resort 
 json.n resort.name 
 json.sy resort.try(:snow_reports).last.try(:snow_valley) if 
 resort.snow_reports 


How many snow reports does a typical resort have? I ask because you're 
loading *all* of them with the `includes` above, but only using the last 
one. If you've got 2000 resorts and each one has 100 reports or so, that 
means instantiating 20 SnowReport objects, and that is not going to be 
fast.

--Matt Jones
 

 json.st resort.try(:snow_reports).last.try(:snow_summit) if 
 resort.snow_reports 
 json.center do 
 json.lat resort.centroid.lat 
 json.lon resort.centroid.lon 
 end 
   end 
 end 


   Rendered resorts/find.json.jbuilder (1649.0ms) 
 Completed 200 OK in 1889ms (Views: 1593.1ms | ActiveRecord: 77.8ms | 
 Solr: 0.0ms) 
 In development mode the request takes 5s in chrome to run. 

 The first thing I ve done to speed up is changing the json gem to 

   gem 'oj' 
   gem 'oj_mimic_json' 

 It speeds up slightly but not enough. I also tried active model 
 serialization wich was about the same time, so I prefer to stick to 
 jbuilder since it is convenient to assemble json objects. 
 So how can I speed up rendering? 

 Help is highly appreciated since I am stuck for a week now. 

 -- 
 Posted via http://www.ruby-forum.com/. 


-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/2f7a3cb3-6779-41d6-9e66-fcf3a3ede17d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Bundle Install Fails on SSL connect for Rake gem

2014-12-11 Thread Matt Jones


On Wednesday, 10 December 2014 06:06:23 UTC-6, Cindi wrote:

 Hi Jason - yes, I did actually search some more on Google and found a 
 similar post with that same answer:

 gem source -r https://rubygems.org/
 gem source -a http://rubygems.org/
 bundle install

 Now it goes through without error.


PLEASE DON'T DO THIS. Downloading and running code from an insecure link 
automatically is a short slip'n'slide to being hacked.

If you're on OS X, check out this post for some troubleshooting steps:
http://mislav.uniqpath.com/2013/07/ruby-openssl/

If you're on another OS, check into what you need to do to update the CA 
cert bundle in the operating system.

The underlying issue is that the OpenSSL library can't validate the 
certificate rubygems.org is sending.

--Matt Jones

 

 On Monday, December 8, 2014 3:40:46 PM UTC-5, Jason FB wrote:

 Cindi,

 1) did you try this: 
 http://stackoverflow.com/questions/10246023/bundle-install-fails-with-ssl-certificate-verification-error

 2) Tweet @rubygems_status or @dwradcliffe if you think the problem is on 
 their end. (but more likely is that you're using an old version of bundler 
 as explained in the link above)

 -Jason




 On Dec 8, 2014, at 1:18 PM, Cindi cvin...@gmail.com wrote:

 Hello - I'm just getting started with Rails, been a ColdFusion programmer 
 for 10+ years. I'm trying to install Rails and get set up on my local dev 
 and it mostly worked, except at the very end of the install using 
 RubyInstaller, I get this message about a particular Gem that can't be 
 installed:

 Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 
 state=SSLv3 read
 server certificate B: certificate verify failed (
 https://rubygems.org/gems/rake-
 10.4.2.gem)
 An error occurred while installing rake (10.4.2), and Bundler cannot 
 continue.
 Make sure that `gem install rake -v '10.4.2'` succeeds before bundling.

 Does anyone know how I could fix that error?

 I was able to go to the URL and download the gem file directly, but not 
 sure how to install it so that the Bundle installer will see that it's been 
 put in and finish its installation routine when I run bundle install.

 Any help would be very much appreciated.

 Thanks!
 Cindi





 -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-ta...@googlegroups.com.
 To post to this group, send email to rubyonra...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/08700e58-3e8d-48e3-82d4-d7f990769411%40googlegroups.com
  
 https://groups.google.com/d/msgid/rubyonrails-talk/08700e58-3e8d-48e3-82d4-d7f990769411%40googlegroups.com?utm_medium=emailutm_source=footer
 .
 For more options, visit https://groups.google.com/d/optout.


 

 Jason Fleetwood-Boldt
 te...@datatravels.com
 http://www.jasonfleetwoodboldt.com/writing

 All material © Jason Fleetwood-Boldt 2014. Public conversations may be 
 turned into blog posts (original poster information will be made 
 anonymous). Email ja...@datatravels.com with questions/concerns about 
 this.
  


-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/dc6248fc-9c4b-49ad-a247-f2d66cb38a09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] Re: user stores - how to setup in theory

2014-12-11 Thread Matt Jones


On Wednesday, 10 December 2014 21:08:47 UTC-6, der_tom wrote:

 well, i do have store_id's and so on for my users, respectively the 
 product_ids and so forth. what im not sure about is how to do the payments. 
 i have my paypal-keys so users can check out on my store, but how would i 
 offer that for the user-to-user scenario? would i just redirect them to 
 their paypal or whatever payment gateway url? not sure...


Some processors offer a solution that to let you attach to other user's 
payment accounts securely - Stripe Connect is one such 
service: https://stripe.com/connect

Paypal may have something similar.

--Matt Jones
 

 On Wed, Dec 10, 2014 at 6:30 PM, Norm Scherer norms...@earthlink.net 
 javascript: wrote:

  Sounds like an opportunity to blaze a trail!

 Norm


 On 12/10/2014 02:57 PM, tom wrote:
  
 anyone?  

  thx

  
 On Fri, Dec 5, 2014 at 1:49 PM, tom toma...@gmail.com javascript: 
 wrote:

 hi, 

  i have an rails app and users can pay to 'my' paypal account via 
 active merchant.

  now i want to expand and allow users to have their own store , but im 
 not sure how to deal with the users - store payments, aka a users buys from 
 another users 'store', how would i set this up?

  any ideas welcome...

  
  thx

   
  -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-ta...@googlegroups.com javascript:.
 To post to this group, send email to rubyonra...@googlegroups.com 
 javascript:.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/CADQqhMdmGnG-QmnDEvbYXVjaKGNHLJmjyD3TmanfmrQC4K89yg%40mail.gmail.com
  
 https://groups.google.com/d/msgid/rubyonrails-talk/CADQqhMdmGnG-QmnDEvbYXVjaKGNHLJmjyD3TmanfmrQC4K89yg%40mail.gmail.com?utm_medium=emailutm_source=footer
 .
 For more options, visit https://groups.google.com/d/optout.


  -- 
 You received this message because you are subscribed to the Google Groups 
 Ruby on Rails: Talk group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to rubyonrails-ta...@googlegroups.com javascript:.
 To post to this group, send email to rubyonra...@googlegroups.com 
 javascript:.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/rubyonrails-talk/5488D7B3.2070101%40earthlink.net
  
 https://groups.google.com/d/msgid/rubyonrails-talk/5488D7B3.2070101%40earthlink.net?utm_medium=emailutm_source=footer
 .
 For more options, visit https://groups.google.com/d/optout.




-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/e166316b-34f3-4a18-bf30-b6e3f9f0308b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] RoR Associations - has_many :through valid or invalid usage?

2014-12-11 Thread Matt Jones


On Thursday, 11 December 2014 09:34:12 UTC-6, Jason FB wrote:

 Jorge, 

 Although I have heard of people using a has_many in some cases when the 
 actual domain model might want a has_one (for example, if your business 
 rule is that the association can have only one at a time and you want to 
 keep the old join table records around with an expired field), generally 
 I would recommend using has_one where has_one is appropriate.

 has_one shouldn't preclude you from being able to create many-to-many 
 relationships on the table B (or rather from B-C), nor should it disable 
 you from being able to join together multiple eager loading associations in 
 your finder. 

 It will however change the naming of your relationships, and it may mean 
 you wind up with some law-of-demeter violations down the road. 

 In short, I would recommend using a has_one unless you have a compelling 
 reason to do it with has_many. Two examples of compelling reasons: 1) You 
 want to preserve old join records like I said above, or 2) You will want to 
 change this relationship to many-to-many soon (within 3 months) and you 
 want to plan for that change. 

 Take a step back and consider that all Rails associations are doing are 
 adding utility methods to your object. How you use them, and how elegant 
 you find the code that is produced, is subjective and at the end of the day 
 still in your court. So use them as best you can to make the most elegant 
 code you can. (Performance considerations aside)

 On a side note, I would strongly encourage you to look into Active Model 
 serializer to encapsulate the serialization logic. 

 Finally, I would note that one little trick you can do to enforce a 
 has_one-like behavior while actually using has_many is in your join model 
 you could use validates_uniqueness_of to enforce that the join table has 1 
 and only 1 record for a User, like so:

 class Memberships
   belongs_to :user
   belongs_to :club
   validates_uniqueness_of :user
 end


This won't work, unfortunately - `validates_uniqueness_of` is expecting a 
column name. Swapping in :user_id would, though.

 



 On Dec 11, 2014, at 1:20 AM, Jorge M. li...@ruby-forum.com javascript: 
 wrote:

 Hello everyone,

 I came across with the following case and I was wondering if using a
 has_many through association is a valid solution.

 Let's say we have three models: A, B and C. The association between
 model A and model B is a 1 to 1 association with B having a Foreign Key
 to A. Now, the association between B and C is a 1 to many association
 with C having a Foreign Key to B. There's an action where I need to
 create an xml representation of some of the properties of each instance
 in a collection of A objects. Additionally, for each instance of A, I
 need to append to its serialized representation two properties from
 each instance of C. This C instance is associated somehow to the A
 instance through an instance of B.

 To create the xml for each instance of A, I will need to iterate over
 each  A instance, for each A instance I will need to read two
 attributes of its corresponding C instances. I want to avoid
 unnecessary trips to the database, therefore, I would like to load the
 A instances together with its somehow corresponding C instances outside
 the loop for the xml creation. I thought to add a has_many through
 association in A like this:

 class A  ActiverRecord::Base
  has_many :cs, through: :b
 end

 This is missing a part. The `through` option takes the name of another 
association on the same class. If I'm reading you correctly, your models 
look something like this:

class A  ActiveRecord::Base
  has_one :b
  has_many :cs, through: :b
end

class B  ActiveRecord::Base
  belongs_to :a
  has_many :cs
end

class C  ActiveRecord::Base
  belongs_to :b
end

In this case, you can certainly load As together with the corresponding Cs 
using `include`:

a_ids = [1,2,3,4] # presumably you start with ids, or some other data 
sufficient to find records

all_the_as = A.include(:cs).find(a_ids) # this loads the specified A 
records, together with all their corresponding C records

The above code will load ALL the A records at once. If this isn't a good 
idea (maybe a_ids has 30k ids in it...) then read up on find_each / 
find_in_batches to do things more efficiently.

--Matt Jones

 so later I could do the following:

 as = A.all.includes(:cs)
 as.each do |a|
  xml.prop_1 a.prop_1
  xml.prop_2 a.prop_2
  a.cs.each do |c|
xml.prop_3 = c.prop_3
xml.prop_4 = c.prop_4
  end
 end

 that way, I avoid some unnecessary trips to the database. However, I am
 not sure if this approach is correct. According to the Rails
 documentation, the examples about the has_many :through association
 illustrates its usage when B has a 1 to many association to both A and
 C, in other words, a Foreign Key to A and C respectively. The
 association in my case between A, B and C is different. So I am not
 sure if adding a has_many through in my

[Rails] Re: Why does this test fail.

2014-12-08 Thread Matt Jones


On Sunday, 7 December 2014 11:50:57 UTC-6, Roelof Wobben wrote:

 Hello, 

 Sorry for the double post but on reddit nobody seems to have the solution. 

 im following the agile web developement book but then with my own layout. 

 Now am at chapter 9 where a shopping card is added. But as soon as I try 
 to test the card I see this error 

 LineItemsControllerTest#test_should_create_line_item:
 RuntimeError: @controller is nil: make sure you set it in your test's 
 setup method. 

 my code can be found here : *https://github.com/roelof1967/commerce-try* 
 https://github.com/roelof1967/commerce-try

 Who can help me figure out why this test is failing. According to the book 
 it must all be successfull. 

 Roelof


The file in app/controllers/concerns is not named correctly - it declares a 
`CurrentCart` module, but is named `current_card.rb`. Fixing that makes all 
the tests pass.

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/aa90b74b-f550-41cd-9056-a77ca944822f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Active Record - Null Forms for nil primitives and associations

2014-11-30 Thread Matt Jones
, if you've got a string that shouldn't ever be nil, and you 
*can't* (for some reason) just declare it default '' not null, you can do 
something like this:

class SomeModel  ActiveRecord::Base
  def attribute_that_cant_be_nil
super || ''
  end
end

(similarly with setters, if writing empty strings is not desired)

If you have an association that you want to pop into existence when 
referenced, as in the user profile thing:

class User  ActiveRecord::Base
  has_one :profile

  def profile
super || build_profile
  end
end

With this, you can happily refer to `@user.profile` and either get the 
existing record or a newly-instantiated one.

If you were feeling really clever, you could even override a particular 
accessor (as above) to return a NullAssociationObject, but there's going to 
be a lot of plumbing required to make that object work all the places a 
model normally would...

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/fd05afe3-ffa5-41fd-ad63-26f51573a409%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: activerecord : undefined method stringify_keys error

2014-11-26 Thread Matt Jones


On Tuesday, 25 November 2014 03:58:01 UTC-5, Maneesh M P wrote:


 Hello,
   
   I am trying to fetch instances details from amazon and trying to store 
 in local mysql db. I am able to fetch all the details from amazon, but 
 while storing the data in mysql i am getting the error undefined method 
 `stringify_keys'  at two places [which ever gets executed first]
   
   Below is my code, can anyone please help me to resolve this error?  [ I 
 marked error in red]

 class Ec  ActiveRecord::Base
attr_accessible :instance_id, :name, :public_ip_address, 
 :availability_zone, :state, :created_at, :flavor_id, :account
def sync
  properties = Array.new
  instance = Ec.new
  connection_dev = Fog::Compute.new({
:provider = 'AWS',
:aws_access_key_id= '###',
:aws_secret_access_key= ##'
})

dev_instances_list = connection_dev.servers.all

dev_instances_list.each do | inst|
 begin
   instance[:instance_id] =  inst.id
   instance[:name] =   (inst.tags['Name'].to_s.empty?)? NA : 
 inst.tags['Name']
   instance[:public_ip_address] =  inst.public_ip_address
   instance[:availability_zone] =  inst.availability_zone
   instance[:state] =  inst.state
   instance[:created_at] =  inst.created_at
   instance[:flavor_id] =  inst.flavor_id
   instance[:account] =  abc
   #instance.save
   properties.push(instance)
 rescue
 puts exception
 end
end
   update_instance_details(properties)
end

def update_instance_details(properties)
updated_list = Array.new
to_store = Hash.new
up = Ec.new
Ec.find_each do |existing|
   to_store = properties.select{|a| a[:instance_id] == 
 existing.instance_id}


`properties` here is an Array. `select` is always going to return an Array, 
even if one or no elements match.

  if(to_store.nil?)


So this will never work - if the instance is entirely missing, `to_store` 
will be `[]`.
 

 #someone has deleted this instance from amazon
 puts Removing the record
 existing.delete
   else
   #update existing record from amazon if there any changes
 *Ec.update(existing.id http://existing.id, to_store) 
  //Errror line*


And then `update` is expecting a hash, not an Array - giving the error 
you've noted.

You may want `find` instead of `select` when extracting an instance's 
details from `properties`. This will return the *element* instead of an 
Array.

Example:

a = [1,2,3,4]
a.select { |el| el == 3 } # = returns [3]
a.find { |el| el == 3 } # = returns 3

For both cases, I'd recommend investigating exactly what class the values 
in `dev_instances_list` are. 

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/8dca5134-48c1-4846-8d3d-6935721a64a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: locals with partial

2014-11-24 Thread Matt Jones


On Sunday, 23 November 2014 08:38:39 UTC-5, Ruby-Forum.com User wrote:

 My partial code: 
 view/clubs_registration/clubs/_dropzone_pictures.html.erb 

 %= hidden_field_tag :club_id, name: :club_id, value: club_id % 


`hidden_field_tag` takes three arguments - name, value, and 
options. 
http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-hidden_field_tag

In your case, it would look like:

%= hidden_field_tag :club_id, club_id %

The third argument is omitted, since you're only looking to set name, id 
and value on the resulting tag.

--Matt Jones
 

 My initial view code: 
 view/clubs_registration/clubs/test_dropzone_pictures.html.erb 


 %= render partial: 'dropzone_pictures', :locals = { :club_id = 
 @club.id } % 


 What I really want to do is retrieve the value of club_id from my 
 jquery: 


 console.log($(#club_id).val());  //-  {:name=:club_id, 
 :value=11500} 


 I just want the value 11500. How should I do that please? 

 -- 
 Posted via http://www.ruby-forum.com/. 


-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/ea380692-1a4e-402a-b06b-e465d09147aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Any reason to use minitest instead of Rspec

2014-11-21 Thread Matt Jones


On Thursday, 20 November 2014 14:13:55 UTC-5, Roelof Wobben wrote:

 Hello, 

 I try again to learn ruby and Im following now Agile Web development in 
 Rails 4

 I see that the author uses minitest to test models.

 Is there any reason to use minitest  instead of Rspec to test models and 
 controllers. 


Both tools will do the job, but my guess is that minitest was selected for 
this because it is simpler to explain to new developers. In other words, 
the expressive DSL that makes rspec nice to use after you know what's going 
on can also be confusing to people who've never encountered it before.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/6bb57d78-1722-42eb-a32d-1fec09fc5489%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: date_select - params ok but nil

2014-11-20 Thread Matt Jones


On Wednesday, 19 November 2014 17:40:50 UTC-5, der_tom wrote:

 hi,

 im kinda stuck...

 %= form_for(@event) do |f| %
   p
 %= f.label :from_date %br /
 %= date_select :event, :from_date %
   /p


 .

 def create
 p params[:event].nil?
 p params[:event][:name]
 p params[:event][:from_date]

 if params[:event][:from_date].empty?
   params[:event][:from_date] = Date.today
 end
 ...
 --
 Started POST /events for 127.0.0.1 at 2014-11-19 17:37:09 -0500
 Processing by EventsController#create as HTML
   Parameters: {utf8=✓, 
 authenticity_token=JannWb1XCE12AKW4KlR56LAAmIOG1raHJh1ss4v0RBA=, 
 event={name=, from_date(1i)=2014, from_date(2i)=11, 
 from_date(3i)=19, to_date(1i)=2014, to_date(2i)=11, 
 to_date(3i)=19}, commit=Create}


 -- why are my event date attributes nil/blank?

The date is not sent as a single attribute, but rather one per dropdown 
that date_select sends (thus from_date(1i) etc).

When those attributes are assigned to your model, they are combined into a 
single object by ActiveRecord.

You can either check for the subparts explicitly, or move the default to 
today behavior to the model instead.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/199cc138-1098-47ef-821d-5a5a5f297345%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Metaprogramming Q: Calling an external class method on after_save

2014-11-14 Thread Matt Jones


On Thursday, 13 November 2014 23:37:40 UTC-5, Debajit Adhikary wrote:

 I have the following classes:

 class AwardBase
 class AwardOne  AwardBase
 class Post  ActiveRecord::Base

 The Post is an ActiveRecord, and the Award has a can_award? class method 
 which takes a post object and checks to see if it meets some criteria. If 
 yes, it updates post.owner.awards.

 I know I can do this using an Observer pattern (I tested it and the code 
 works fine). However, that requires me to add additional code to the model. 
 I'd like not to touch the model at all if possible. What I'd like to do is 
 run the Award checks like this (the trigger will be invoked at class load 
 time):

 class AwardOne  AwardBase
   trigger :post, :after_save

   def self.can_award?(post)
 ...
   end
 end

 The intention with the above code is that it should automatically add 
 AwardOne.can_award? to Post's after_save method


You could do this with code like (not tested):

class AwardOne  AwardBase
  def self.trigger(klass, callback, method)
us = self # this may not be needed
klass.to_s.camelize.constantize.send(callback) do |record|
  us.send(method, record)
end
  end

  trigger :post, :after_save, :can_award?

end

But seriously, DON'T DO THIS. Callbacks are already one of the more 
confusing features of AR, and confounding that by over-metaprogramming is 
going to obscure things further.

Even re-opening the Post class in award_one.rb and adding the callback in 
the standard style would be clearer than this, but I'd recommend just using 
the version you've already written (below). 

--Matt Jones

 

 class Post  ActiveRecord::Base
   after_save :check_award

   def check_award
 AwardOne.can_award?(self)
   end
 end





-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/59592b58-9f3f-4374-b37a-c6cea7372735%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: heroku not supporting website from othr web source..

2014-11-13 Thread Matt Jones


On Thursday, 13 November 2014 02:35:42 UTC-5, mukul saharia wrote:

 hello friends,
 i am working with rails and i want to load some java script components 
 from other web source and render it in my web site which is hosted on 
 heroku.
 but heroku is not loading components from other web source.
 is there any solution for it.

 i copied this code in view. This java script is rendaring on localhost but 
 not working on heroku.
 div
 script type=text/javascript src=
 http://app.ecwid.com/script.js?5*77; charset=utf-8/script
 script type=text/javascript 
 xVCategories(id=my-vCategories-5***7); /script
 /div


It's nearly-impossible to troubleshoot something like this based solely on 
the description not working on Heroku. 

* What messages do you get in the browser console when you load the page 
from Heroku? 

* Does the server at app.ecwid.com implement some kind of licensing? Some 
SaaS products will check the Referer header and deny access to requests 
coming from unlicensed domains that aren't localhost.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/e9e3716e-826f-4f1a-bd37-22ec181e0b1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Getting doublets of records while using an offset

2014-11-05 Thread Matt Jones


On Tuesday, 28 October 2014 09:14:56 UTC-4, Max Grønlund wrote:

 Consider this schenario where I'm having pagination on a page

 @recordings =  Recording.order(:title).page(params[:page]).per(4)
  puts params[:page]@recordings.each do |recording|
   puts recording.id 

 end 

 page 3
   Recording Load (4.0ms)  SELECT  recordings.* FROM recordings   ORDER BY 
 recordings.title ASC LIMIT 4 OFFSET 8
 1032
 952
 1063
 1166  notice 

 page 4

 Recording Load (4.3ms)  SELECT  recordings.* FROM recordings   ORDER BY 
 recordings.title ASC LIMIT 4 OFFSET 12
 1166   notice 
 1168
 657
 756

 So record 1166 is on both pages

 
 how I solved it

 class Uniqifyer
   def self.uniqify not_uniq_field
 uniq_string =   not_uniq_field.to_s
 # secure ordering e.g [13 , 120, 140 ] not [120, 13, 140]
 prepend_str =  '00'.byteslice(0...-uniq_string.length)
 prepend_str + uniq_string + '_uuid_' + 
 UUIDTools::UUID.timestamp_create().to_s
   endend
 #in model:before_commit :uniqifydef uniqify
  self.MY_UNIQ_STRING = Uniqifyer.unigify self.MY_NOT_UNIQ_FIELDend
 # in controllerdef index
  @ordered_records = 
 MY_MODEL.order(MY_UNIQ_STRING).page(params[:page]).per(24)end
 # Notice! Rube is so cool you can directly convert a uniqifyed number like 
 thisnumber = MY_UNIQ_STRING.to_i


 not so elegant
 any suggestions are welcome

 Are you on Postgresql? It takes a very literal interpretation of the SQL 
standard when row order isn't uniquely specified:

http://dba.stackexchange.com/questions/48989/postgresql-indeterminate-ordering-of-results

Sorting on something that's reliably unique (even just `id` along with 
`title`) should sort this out.

--Matt Jones
 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/59e2a6bd-be59-4ad0-91cd-32e005b7ca5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: form_for not passing id?

2014-11-03 Thread Matt Jones


On Sunday, 2 November 2014 20:57:43 UTC-5, Ruby-Forum.com User wrote:

 Hi, 
 When I try to update a field using the update button I am getting the 
 error: No route matches [PATCH] /profile.  Its obviously missing the 
 /:id but I can't figure out why... 

 I am using a form_for in an edit view. 

 %= form_for @profile, :html = { :class = 'form-horizontal '} do |f| 
 % 
   ... 
 %= f.submit 'Update', :class = 'btn btn-primary' % 
   ... 
  % end % 

 @profile contains #Profile:0x0104c26398 as it should. 

 routes contains: resources :profiles  and the resulting routes appear OK 


From the route it's generating, I suspect you have a `resource :profile` 
someplace above this. That matches the controller actions you're showing, 
which use `current_user.id` instead of `params[:id]`. You'll likely need to 
specify the URL explicitly to `form_for`.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/36c37534-b55b-431b-a1a5-e1e18b842024%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Rails] rails version and copying app

2014-10-31 Thread Matt Jones


On Thursday, 30 October 2014 14:19:46 UTC-4, Robert Fitzpatrick wrote:

 Colin Law wrote: 
  That tells you it is rails 4.0.0 as activemodel is one of the 
  components.  However, rather than seeing what versions are installed 
  (there could be more than one version of the gems installed) look in 
  the file Gemfile.lock in the applications root folder and you will see 
  what versions it /requires/. 

 I have several GIT entries in the Gemfile.lock file and a list of gems 
 after the following lines, but this list looks much more extensive than 
 'gem list' shows ... 

 GEM 
remote: https://rubygems.org/ 
specs: 
  list of gems 

 Then under DEPENDENCIES, I see ... 

 rails (= 3.2.13) 

 Does that explain my rails version? I don't see any references to 4.0.0. 

  I suggest you work right through a good tutorial such as 
  railstutorial.org (which is free to use online) which will show you 
  the basics of rails.  A few days spend doing that will save you time 
  in the long run. 

 Yes, I've already found that and been reading, thanks. 

  If you want this for development work then I suggest you install rails 
  using rvm [1] 
  That will give you a complete working setup in a few minutes. 

 I used rvm to install same ruby-1.9.3-p392 as the VPS, following a doc 
 here... 


 https://www.digitalocean.com/community/tutorials/how-to-install-rails-apache-and-mysql-on-ubuntu-with-passenger
  

 After all setup in Apache, I am getting this Passenger application error 
 in the browser 

 cannot load such file -- bundler/setup (LoadError) 
   
 /usr/share/ruby-rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in
  

 `require' 
   
 /usr/share/ruby-rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in
  

 `require' 
   
 /usr/share/ruby-rvm/gems/ruby-1.9.3-p392/gems/passenger-4.0.53/lib/phusion_passenger/loader_shared_helpers.rb:263:in
  

 `block in run_load_path_setup_code' 
   
 /usr/share/ruby-rvm/gems/ruby-1.9.3-p392/gems/passenger-4.0.53/lib/phusion_passenger/loader_shared_helpers.rb:366:in
  

 `running_bundler' 
   
 /usr/share/ruby-rvm/gems/ruby-1.9.3-p392/gems/passenger-4.0.53/lib/phusion_passenger/loader_shared_helpers.rb:261:in
  

 `run_load_path_setup_code' 
   
 /usr/share/ruby-rvm/gems/ruby-1.9.3-p392/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:100:in
  

 `preload_app' 
   
 /usr/share/ruby-rvm/gems/ruby-1.9.3-p392/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:158:in
  

 `module:App' 
   
 /usr/share/ruby-rvm/gems/ruby-1.9.3-p392/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:29:in
  

 `module:PhusionPassenger' 
   
 /usr/share/ruby-rvm/gems/ruby-1.9.3-p392/gems/passenger-4.0.53/helper-scripts/rack-preloader.rb:28:in
  

 `main' 

 Perhaps I need to get some more gems installed? I did a 'gem install 
 bundle' and still get the error. My gem list is this so far on the dev 
 server I am trying to setup, not sure if this error is affecting things 
 as well... 

 root@media:/etc/apache2# gem list 
 /usr/share/ruby-rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/yaml.rb:56:in 
 `top (required)': 
 It seems your ruby installation is missing psych (for YAML output). 
 To eliminate this warning, please install libyaml and reinstall your ruby. 

 *** LOCAL GEMS *** 

 bundle (0.0.1) 
 bundler (1.7.4) 
 daemon_controller (1.2.0) 
 passenger (4.0.53) 
 rack (1.5.2) 
 rake (10.3.2) 

 On the production server, I have... 

 *** LOCAL GEMS *** 

 activemodel (4.0.0) 
 activerecord (4.0.0) 
 activerecord-deprecated_finders (1.0.3) 
 activerecord-mysql-adapter (0.0.1) 
 activesupport (4.0.0) 
 arel (4.0.0) 
 atomic (1.1.13) 
 bigdecimal (1.1.0) 
 builder (3.1.4) 
 bundler (1.3.5) 
 i18n (0.6.5) 
 io-console (0.3) 
 json (1.5.5) 
 minitest (4.7.5, 2.5.1) 
 multi_json (1.7.9) 
 mysql (2.9.1) 
 rake (0.9.2.2) 
 rdoc (3.9.5) 
 thread_safe (0.1.2) 
 tzinfo (0.3.37) 

 But again the list in the Gemfile.lock file lists many more. Just trying 
 to get a grasp of where to go from here, what is need to get this copy 
 to run, appreciate any help! 



My guess is that the system ruby (the one you get when you type gem list 
by default) is NOT the one the app is using. You may want to check the app 
directories for a .rvmrc or .ruby-version file, or the nginx config for 
a setting telling it which Ruby to use...

--Matt Jones
 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/b1bbb746-9f48-4685-ba87-9921e43effda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: has_many through association on unsaved objects

2014-10-31 Thread Matt Jones


On Thursday, 30 October 2014 13:56:51 UTC-4, Markus D. wrote:

 Hello,

 I just stumbled upon a behaviour about associations I do not really 
 understand why Rails/ActiveRecord cannot get the connection. Using 
 activerecord (4.2.0.beta2).

 To describe it, lets work with theses models:

 class User  ActiveRecord::Base
 has_many :project_participations
 has_many :projects, through: :project_participations, inverse_of: :users
 end

 class ProjectParticipation  ActiveRecord::Base
 belongs_to :user
 belongs_to :project

 enum role: { member: 0, manager: 1 }
 end

 class Project  ActiveRecord::Base
 has_many :project_participations
 has_many :users, through: :project_participations, inverse_of: :projects
 end


 A user can participate in many projects with a role as a member or a 
 manager. The connecting model is called ProjectParticipation. 

 I now have a problem using the associations on unsaved objects. The 
 following commands work like I think they should work:

 # first example

 u = User.new
 p = Project.new

 u.projects  p

 u.projects
 = #ActiveRecord::Associations::CollectionProxy [#Project id: nil]

 u.project_participations
 = #ActiveRecord::Associations::CollectionProxy [#ProjectParticipation id: 
 nil, user_id: nil, project_id: nil, role: nil]


 So far so good - AR created the ProjectParticipation by itself and I can 
 access the projects of a user with u.projects. 

 But it does not work if I create the ProjectParticipation by myself:

 # second example

 u = User.new
 pp = ProjectParticipation.new
 p = Project.new

 pp.project = p # assign project to project_participation

 u.project_participations  pp # assign project_participation to user

 u.project_participations
 = #ActiveRecord::Associations::CollectionProxy [#ProjectParticipation id: 
 nil, user_id: nil, project_id: nil, role: nil]

 u.projects
 = #ActiveRecord::Associations::CollectionProxy []


 Why are the projects empty? I cannot access the projects by u.projects 
 like before, even the ProjectParticipation is there.

 But if I go through the participations directly, the project shows up:

 u.project_participations.map(:project)
 = [#Project id: nil]

 Shouldn't it work like the first example directly:
 u.projects returning me all projects not depending on whether I create the 
 join object by myself or not? Or how can I make AR aware of this?


`u.projects` is going to load things from the database if the record is 
saved, but otherwise it will only return objects you've explicitly stored 
in it.

The `through` association is not the same as just mapping `:project` over 
project_participations.

Can you describe what you're trying to do in more detail? There's likely a 
way to make AR do the right thing.

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/301e3be4-1ede-43c5-8396-ac374bcd3344%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Need Quality E-Commerce Samples

2014-10-30 Thread Matt Jones


On Wednesday, 29 October 2014 18:17:10 UTC-4, john...@gmail.com wrote:

 My boss is finally willing to listen to moving to a quality open sourced 
 platform for our e-commerce web site, but she needs 'concrete examples' to 
 believe that moving to ruby on rails is a good solution.  And she needs 
 'e-commerce' pages (i.e. telling her twitter is built in rails doesn't 
 impress her), preferably in the natural food industry.

 We currently have a company that 'built' our website in PHP and we don't 
 own our code, nor do we have access to the data (which drives me batty).  
 They were recently purchased and the new owner is attempting to green mail 
 us and it's an opportunity to get my boss to move to a better base where we 
 own all the data and the code of the web site.  I'm a 'pre-beginner' in 
 rails.  I know enough to get started, but not enough to build a truly 
 dynamic website, let alone a fully functional e-commerce with a front and 
 back end.

 I was hoping people could give me some examples or a site that lists sites 
 built in rails?


+1 to the existing recommendations for Spree and Shopify.

But seriously, the premise is fairly silly: the toolset used to build a 
site has a minimal to nonexistent effect on its external appearance. It 
would be like asking a (building-style, not software-style) architect I'm 
thinking about building my next house out of wood. Can you show me some 
previous projects that used wood?.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/118721eb-d000-40b6-8378-f6e44fb3059a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Creating multiple views for a database table .. routing not working

2014-10-29 Thread Matt Jones


On Monday, 27 October 2014 21:17:38 UTC-4, Sonali Katara wrote:

  I have a single table in which I store favourite dishes of users. A user 
 can have more than one entries in the table. I have generated a view to 
 show all the entries in the table but how do I create a view to show just 
 the list of users. I don't have a table saving the users so I have to use 
 DISTINCT to get the names of the users from my one and only table

 I appraoched this by creating a new route
 /foodsIlike/user_list

 get '/foodsIlike/user_list' = 'foodsIlike#user_list', :as = 'user_list'

 instead of going to the user_list it tries to find a record with 
 :id=user_list as that is what it would do to show one record


I'd also recommend reconsidering your schema like the other replies, but 
the bigger problem here is route order. You're getting this behavior 
because you have the route that matches `/foodsIlike/:id` is *before* the 
one that matches `/foodsIlike/user_list` in config/routes.rb

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/bf73e36a-3369-4f24-846a-599db950b5f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Ruby on Rails (ROR) Development Services

2014-10-17 Thread Matt Jones


On Thursday, 16 October 2014 09:18:13 UTC-4, Ruby-Forum.com User wrote:

 Panzer Technologies is well prepared to provide the best staffing 
 solutions and when it comes to ruby on rails development, it stands out 
 as a distinguished company, with required expertise in ROR. 

 To get more information please visit our website @ 


Tell your website people that *bolding random words* isn't worth pagerank, 
if it ever was...

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/a2854f64-6500-45b2-a665-0f36e5f238d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Radio button required field class

2014-10-17 Thread Matt Jones


On Friday, 17 October 2014 03:46:49 UTC-4, M,Gopi M.gopinath wrote:

 Hi,

 I need to add a required class in gender radio button. How this can be 
 done.

 td colspan=2
 label for=stay_connected_form_genderI am span 
 class=astris*/span/label
 %= f.radio_button :gender, 'm', :class = 'RadioInput' %Male
 %= f.radio_button :gender, 'f', :class = 'RadioInput' %Female
 /td

 classname  = required

 If I am adding like this then it display two validation message for each 
 radio button.

 %= f.radio_button :gender, 'm', :class = 'RadioInput required' %Male
 %= f.radio_button :gender, 'f', :class = 'RadioInput required' %Female

 I need to get a single validation msg if none of the radio button is 
 selected.


What Colin said - there's not a single element for radio buttons. You 
didn't state which Javascript library you're using, but presumably it has a 
solution for radio buttons.

Also note that the ability to not have any of them checked is widely 
supported among browsers but not in keeping with the standard:

http://www.w3.org/TR/html401/interact/forms.html#radio

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/2071bffc-05e4-4956-bb51-f667fe8e0a16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: ActiveSupport::Concern small question

2014-10-12 Thread Matt Jones


On Friday, 10 October 2014 09:08:29 UTC-4, rusik wrote:

  Hello all.

  In this example, as i understand that *included* block is running when 
 Exclaimable module is included in Person and *after* a Person class 
 methods are 'initialized'


No. See below for additional information, but if `include Exclaimable` is 
the first thing in a class definition, only methods defined on the 
declaring class's superclass (Object, in the case of Person) will be 
available.
 

  

 require 'active_support/concern'

  

 module Exclaimable
   extend ActiveSupport::Concern
   included do
 self.new.hello
   end
 end

  

 class Person
   include Exclaimable
   def hello
 puts 'person hello'
   end
 end


 Output: Exception: NoMethodError: undefined method `hello' for 
 #Person:0x0103cbdcd0

 But  i see that, Person class doesn't have hello method, why ? Please, 
 help !


The stuff between `class Person` and `end` is just code. The `hello` method 
isn't available yet because it hasn't been DEFINED yet when `include 
Exclaimable` executes.

 

 So, i can't understand - what diifference between
  

 included do 
  self.new.hello
 end

   
 and class method:
  

 self.included(base)
  base.new.hello
 end


 Both code get same error ( see above )


`self.included` is Ruby's built-in hook. ( 
http://www.ruby-doc.org/core-2.1.3/Module.html#method-i-included ) It gets 
called when the module that declares it is included in another module or 
class.

`ActiveSupport::Concern` adds the `included do` idiom, to make situations 
where one module depends on another more straightforward. See the last 
section of the docs for more:

http://api.rubyonrails.org/classes/ActiveSupport/Concern.html

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/d54def3c-678d-4188-b0e5-63fbec468f8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: display ppt file in rails application

2014-10-10 Thread Matt Jones


On Thursday, 9 October 2014 06:28:30 UTC-4, Ruby-Forum.com User wrote:

 Hello Evereyone...! 

 I am trying to create rails application like slideshare, I had properly 
 upload my ppt file in to database when I want to perform/display that 
 particular presentation file. 

 How can i achieve that without using thirdparties application like 
 upload ppt file into scribd etc.. 

 please anybody suggest me or give some usefull gems for that...! 


ruby_powerpoint is probably a decent place to start:

https://github.com/pythonicrubyist/ruby_powerpoint

Note that it only works with new-style pptx files. 

For the old format, GOOD LUCK. They are poorly-documented and tricky to 
work with. Tools like Docsplit (http://documentcloud.github.io/docsplit/) 
might do what you want for these, but they depend on LibreOffice - and 
correspondingly, can only read PPT files that work in LibreOffice.

One gotcha: none of these will replicate any of the more complex behaviors 
(animations, transitions). ruby_powerpoint doesn't even give text style 
info back, just text and images.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/b77eefd0-0033-4260-9aff-a5175a12563c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Instance variable looses value upon render

2014-10-09 Thread Matt Jones


On Wednesday, 8 October 2014 11:07:16 UTC-4, Ruby-Forum.com User wrote:

 I have an instance variable, @pages, which needs to be set up in a 
 certain way at the end of several actions, so I thought to be clever and 
 do it in the following way: 

 # In my controller 

 after_action :prepare_admin_home_data, only: 
 [:adm_login,:adm_upload_selected] 

 def adm_login 
   ... 
   render admin_pages_home_path 
   ... 
 end 

 def prepare_admin_home_data 
   @pages=Dir[#{AMP_DIR}/*] 
   logger.debug(+++ pages #{@pages.to_s}) 
 end 

 I can see from the logs, that @pages got the right value, but in my 
 view, it is nil. It seems that the HTML code is constructed before the 
 after_action is executed. 


Correct. Code in `after_action` callbacks can examine and mutate the 
about-to-be-sent response, but the render has already occurred.
 

 I understood the render() function in that way, that it only sets up 
 which ERB template is supposed to be used, but actual rendering would 
 occur only when the action has finished. Did I get this wrong? 


When you call `render` the render happens immediately. If you return from 
an action *without* rendering or redirecting, the default behavior will be 
executed by ActionPack (rendering the template with the same name as the 
action).

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/8cd74ec1-4668-423b-ad0a-50056883d81e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Ruby on Rails performance on lots of requests and DB updates per second

2014-10-09 Thread Matt Jones


On Wednesday, 8 October 2014 09:04:29 UTC-4, LZ Olem wrote:

 I'm developing a polling application that will deal with an average of 
 1000-2000 votes per second coming from different users. In other words, 
 it'll receive 1k to 2k requests per second with each request making a DB 
 insert into the table that stores the voting data.

 I'm using RoR 4 with MySQL and planning to push it to Heroku or AWS.

 What performance issues related to database and the application itself 
 should I be aware of?

 How can I address this amount of inserts per second into the database?

EDIT

 I was thinking in not inserting into the DB for each request, but instead 
 writing to a memory stream the insert data. So I would have a scheduled job 
 running every second that would read from this memory stream and generate a 
 bulk insert, avoiding each insert to be made atomically. But i cannot think 
 in a nice way to implement this.


Don't implement that, certainly not as a first thing. Build something 
straightforward that does what you intend (collecting poll results), then 
load-test it.  Building a hyper-scalable DB layer isn't going to do much 
good until you're sure the layers in front of it (app servers, etc) can 
handle the load.

You may also want to consider what part of these results needs to be 
durable. For instance, if an exact user - vote mapping isn't needed you 
could hack something together with Redis and its INCR command.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/4189e84e-afd0-4de8-bc55-9d102dcbb2d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: How to avoid N+1 queries in Rails each loops?

2014-09-30 Thread Matt Jones


On Monday, 29 September 2014 23:15:36 UTC-4, Austin York wrote:

 In a todo list-style app, I have the following ActiveRecord model method:

 class Task  ActiveRecord::Base
   # ...
   def project_name
 project.tasks.length  0 ? #{project.name} - #{name} : project.name
   end
 end

 The idea is to provide additional project information if there are one or 
 more tasks on the project.

 However, when invoked regularly on views this creates performance concerns 
 (especially with a growing data set).

 What is the best way to optimize this query so that it doesn't create N+1 
 query type issues when invoked from each loops in the view?


+1 what Michał said about eager-loading. One additional tricky thing: 
prefer `size` over `length` for associations and relations. In plain Ruby, 
`size`, `length` and `count` are more or less identical - but for 
ActiveRecord collections they have slightly different meanings:

* `length` is the most straightforward: it's ALWAYS the number of records 
in the collection. If the collection isn't currently loaded, calling 
`length` on it will trigger a SQL query to load all the records.

* `count` is the opposite: it ALWAYS runs a SQL query. It doesn't load 
records, it uses SQL's `COUNT()` function. It can also return things that 
aren't numbers; doing `Task.group(:project_id).count` will give you back a 
hash with `project_id`s as keys and the number of matching tasks as values.

* `size` is the middle: if the collection is loaded, it works like 
`length`. Otherwise it works like `count`...

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/e6771c47-1c12-4e5a-8fe6-73af4d7b26e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Rspec Active Record Problem

2014-09-25 Thread Matt Jones


On Wednesday, 24 September 2014 10:14:02 UTC-4, Ruby-Forum.com User wrote:

 Rspec forum isn't working 

 Rspec is having trouble recognizing where method. 

 Here's the rspec output: 

   NoMethodError: 
undefined method `where' for #Article:0x00066ceb38 
  # 
 /apps/rvm/gems/ruby-2.0.0-p481/gems/activemodel-4.0.10/lib/active_model/attribute_methods.rb:439:in
  

 `method_missing' 
  # 
 /apps/rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.0.10/lib/active_record/attribute_methods.rb:168:in
  

 `method_missing' 
  # 
 /apps/rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.0.10/lib/active_record/querying.rb:9:in
  

 `where' 


 The spec calls index which then calls a public method that uses the 
 following method: 

 class X  ActiveRecord::Base 
   def self.low_level 
 where(:level= 1) 
   end 
 end 

 Any ideas what could be the problem? 


There isn't enough code here to know for sure, but something strange is 
going on with your X class. Line 9 of `active_record/querying.rb` delegates 
the `where` method to `all`. Normally this is a class method that returns a 
Relation object. Does your X class have an `all` class method that's 
overriding that?

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/484b4d9e-fd81-49c3-ada2-c1a0d6bd7a35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Couldn't find 'migration' generator

2014-09-25 Thread Matt Jones


On Thursday, 25 September 2014 03:13:12 UTC-4, M,Gopi M.gopinath wrote:

 Hi,

 I am trying to add a field in a existing table (database) in Rails 2.3.5 
 and ruby 1.8.6.

 I gave a command to generate a migration, Here as follows,

 ruby script/generate migration AddwebToDistributors website:string

 But I am getting a error, saying that Couldn't find 'migration' 
 generator 


Try running the generator without arguments and report what you get back:

ruby script/generate

migration should be in the list that comes back, but perhaps something is 
broken...

--Matt Jones
 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/d8f64b27-305d-4258-888a-9779ac3b8628%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Rails] Re: Migration Trouble

2014-09-19 Thread Matt Jones


On Thursday, 18 September 2014 19:52:05 UTC-4, Ruby-Forum.com User wrote:

 I'm having an issue with one migration.  all other migrations work ok. 

 Here's the output: 
 == 20140905145859 CreateMemberships: migrating 
  
 -- create_table(:memberships) 
- 0.3010s 
 == 20140905145859 CreateMemberships: migrated (0.3011s) 
 === 


 But here's what it looks like in rails c: 
 Loading development environment (Rails 4.0.5) 
 2.0.0-p481 :001  Membership 
  = Membership() 

 Here's the content of the migration: 
 class CreateMemberships  ActiveRecord::Migration 
   def change 
 create_table :memberships do |t| 
   t.string :user_id 

   t.timestamps 
 end 
   end 
 end 


 Any ideas why this one migration has problems? 


If you do `Membership.first` in the console, what happens?

Usually when this sort of weirdness happens to me, it's because some other 
class/module in the app is getting named `Membership`, which makes a real 
mess.

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/0104d282-2906-41a3-86ef-41a6660946f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


  1   2   3   4   5   6   7   8   9   10   >