Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
NotShadowStar
Sep 20, 2000
Plus with namespaces you can define things in the root namespace class and have them filter down automatically, just like you would with ApplicationController. Like

code:
class Admin <ActiveRecord::Base
 before_filter :authenticate_user!, :check_access_level #devise

 def check_access_level
  #'n poo poo
 end
end

class Admin::Post < ActiveRecord::Base
#all methods will be prefixed with authenticate_user! and check_access_level without any work
end

Adbot
ADBOT LOVES YOU

Triggerle
Jun 3, 2001
I went with the separate views for now, which seems very fitting for the scope of my project. I liked the points about namespaces, however, and I will definitely go for namespaces with the next project.

Thanks guys!

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

NotShadowStar posted:

Plus with namespaces you can define things in the root namespace class and have them filter down automatically, just like you would with ApplicationController. Like

code:
class Admin <ActiveRecord::Base
 before_filter :authenticate_user!, :check_access_level #devise

 def check_access_level
  #'n poo poo
 end
end

class Admin::Post < ActiveRecord::Base
#all methods will be prefixed with authenticate_user! and check_access_level without any work
end

Wait.... isn't this supposed to be
code:
class Admin < ActiveRecord::Base
end

class Post < Admin
end
ActiveRecord::Base is being specified twice in your example and I am not sure I've seen it done that way before. What is the advantage?


e: I see. It's so that you can still have a Post class. I get it...

rugbert
Mar 26, 2003
yea, fuck you

NotShadowStar posted:

You really should learn the fundamentals of ActiveRecord associations, because this is really basic stuff.

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

Gotcha, I was missing my foreign key, thanks! Well that makes what I was trying to do ridiculously easy.

So I have my site in good working order. On my laptop anyway. But when I push to heroku it breaks in two spots, again they work fine on my laptop.

First thing that breaks is what I just did, where I gave each user their own gallery.
My associations are right and my controller has:
code:
  def index    
    u = current_user
    @tattoos = u.tattoos.all
  end
heroku logs gives me
code:
ActiveRecord::StatementInvalid (PGError: ERROR:  operator does not exist: character varying = integer
LINE 1: ...     ("images"."type" = 'Tattoo') AND ("images".user_id = 1)
                                                                   ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT     "images".* FROM       "images"  WHERE     ("images"."type" = 'Tattoo') AND ("images".user_id = 1)):
  app/controllers/admin/tattoos_controller.rb:5:in `index'
And another page where Im filtering blog posts based on categories. My controller for the category view is
code:
    @blogs = BlogPost.where(:category => params[:category]).all
and in the view I have <%= @blogs.first.category %> But Im getting an undefined method error. Ive migrated multiple times to make sure the table is up to date (BlogPost has a field called category) but it still breaks.

rugbert fucked around with this message at 20:57 on Jan 26, 2011

hmm yes
Dec 2, 2000
College Slice
That's a common issue with Heroku: Common issues migrating to PostgreSQL. Also, you shouldn't be using an attribute 'type' since it is a reserved word and can often cause problems.

rugbert
Mar 26, 2003
yea, fuck you

atastypie posted:

That's a common issue with Heroku: Common issues migrating to PostgreSQL. Also, you shouldn't be using an attribute 'type' since it is a reserved word and can often cause problems.

Well I have a type field for Image because I have two model inheriting from Image, drawings and tattoos. Im not actually touching 'type' Im letting rails mess with it.


edit - AH see, I mistakenly set the user_id field to a string instead of a integer. thanks!

rugbert fucked around with this message at 21:10 on Jan 26, 2011

NotShadowStar
Sep 20, 2000
Hah, you're running into all the seemingly strange edge 'gotchas' of AR your first time around. I knew some people who were used to MSSQL and were kind of baffled for a while why they couldn't use GUIDs as a primary key.

hmm yes
Dec 2, 2000
College Slice

rugbert posted:

Well I have a type field for Image because I have two model inheriting from Image, drawings and tattoos. Im not actually touching 'type' Im letting rails mess with it.

Durr, sorry :) I saw that as a string called type

dustin10
Jul 24, 2003
So, I am about to start a new project. I usually use php and symfony for my web projects, but I have been tinkering with rails over the last month or so and am intrigued. I know symfony inside and out (pretty much), so I know I can get it done quickly if I go that route.

That being said, I am getting a tad bored with symfony and am thinking about learning rails more in-depth. I guess I just wanted to get some general advice from people who are using rails and maybe have made a similar switch already. Would this transition be relatively smooth? From what I have done so far with rails, it appears to be very similar to symfony, even using most of the same terminology. Any thoughts are appreciated.

rugbert
Mar 26, 2003
yea, fuck you
Ahh OK, Im starting to get it. The undefined method issue I was having was because I didnt have any blogs with defined categories.

So next thing I have to do is make sure if a category isnt chosen then it gets a default cat.

The next thing Im going to figure out is how validations work. I read some book where it said I could put the error message right in the model and flash_messages would display it but its not working. I wanna run home and double check tho.

Triggerle
Jun 3, 2001
Apparently, there are only four url helpers:
code:
stories_url               becomes /stories
story_url(@story)         becomes /stories/1
new_story_url             becomes /stories/new
edit_story_url(@story)    becomes /stories/1/edit
The other RESTful methods are not accessible by url helpers because they would expand to the same urls (just with different http methods). Custom methods cannot be constructed with url helpers.

Now that I know this it makes perfect sense.

This morning, however, when I still didn't know this I read a tutorial on the Internet. In this tutorial someone used the edit helper to deliver a token to the controller's edit method where he would not actually edit anything but call some other methods. Modeling my need to pass a token to the create method after this tutorial lead to me trying for three hours to construct a url helper with various method_controller_url combinations (with and without pluralizations) that all didn't work until I finally figured it out. Good times.

Edit: vvvvvvvv Turns out I was still wrong. It seems you can use url helpers for all GET routes that have been properly set up. So if your rake routes shows for example a welcome_users path then welcome_users_url gives you the link to it. (This also means that I had a case of several cumulative errors in my original code.)

Triggerle fucked around with this message at 12:21 on Jan 27, 2011

Pardot
Jul 25, 2001




Triggerle posted:

url helpers:

If you run rake routes you can get a good idea of the url helpers that are available given your current routes and where they go.

Obsurveyor
Jan 10, 2003

dustin10 posted:

That being said, I am getting a tad bored with symfony and am thinking about learning rails more in-depth. I guess I just wanted to get some general advice from people who are using rails and maybe have made a similar switch already. Would this transition be relatively smooth? From what I have done so far with rails, it appears to be very similar to symfony, even using most of the same terminology. Any thoughts are appreciated.
As a long time PHP dev switching to Rails and not having used symfony, I glanced through a couple of the pages in the gentle intro to symfony and it looks a lot like something of a clone of Rails implemented in PHP. So I guess your transition would be pretty easy. There is still a lot of magic that happens in Rails that can be bewildering at first sight, especially if you do not understand Ruby that well.

I say go for it. Run through the Ruby on Rails Tutorial and you will be sprinting in no time. This is where the Addison-Wesley book "Ruby on Rails 3 Tutorial: Learn Rails by Example" comes from but the author updates it regularly. I personally feel, after just going through my copy of Agile Web Development with Rails, 4th Edition again, that it is a much better whole-life introduction to a very good way to develop for Rails. It is also free if you read it online.

skidooer
Aug 6, 2001

NotShadowStar posted:

I knew some people who were used to MSSQL and were kind of baffled for a while why they couldn't use GUIDs as a primary key.
You have me curious. Why can't you?

I've used GUID primary keys in a Rails/ActiveRecord project before. It was backed by MySQL and not MSSQL though.

NotShadowStar
Sep 20, 2000

skidooer posted:

You have me curious. Why can't you?

I've used GUID primary keys in a Rails/ActiveRecord project before. It was backed by MySQL and not MSSQL though.

Well, you can do it through UUID extensions to AR, but by default design AR only works with integer auto increment primary keys. You also have to ensure that the db engine actually uses UUID instead of a stringified GUID like sqlite3 will do, or AR will just choke and barf on any relations.

skidooer
Aug 6, 2001

NotShadowStar posted:

Well, you can do it through UUID extensions to AR, but by default design AR only works with integer auto increment primary keys. You also have to ensure that the db engine actually uses UUID instead of a stringified GUID like sqlite3 will do, or AR will just choke and barf on any relations.
I just tried creating a fresh Rails project with a sqlite database (all I have handy at the moment) with a string primary key, and it worked just fine. No extensions were added.

NotShadowStar
Sep 20, 2000
Oh yeah, sqlite doesn't have types, I remember now. You can happily store anything in any column regardless of what the table schema says. The sqlite ruby driver converts it based on the table definition.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Obsurveyor posted:

Any recommendations on where to start with choosing an authentication library for Rails 3 that will utilize existing database columns?

Unfortunately, there is simply no way I can re-write everything I have in PHP for the new website I am working on in the time I have. That means I need to pull usernames and passwords from my existing CRM database. I do not need fancy features such as password reminders, resets, roles, etc. I just need something that will block page access based on logged in/not logged in and one other flag about the user's company in the database.

I don't know if you saw this or not but there is a brand new railscast on this topic. It's pretty simple to do and hasn't changed very much since the last time.

http://railscasts.com/episodes/250-authentication-from-scratch

The only thing I would change in this implementation, is making use of more current password hash technology. I just embed the salt directly into the password_hash column. It still makes it impossible to batch-decode a list of hashed passwords, it even makes it more difficult.

So I'd remove the salt column and replace:

code:
  def self.authenticate(email, password)
    user = find_by_email(email)
    if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
      user
    else
      nil
    end
  end
  
  def encrypt_password
    if password.present?
      self.password_salt = BCrypt::Engine.generate_salt
      self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
    end
  end
with:

code:
  include BCrypt

  def self.authenticate(email, password)
    user = find_by_email(email)
    if user && Password.new(user.password_hash) == password
      user
    else
      nil
    end
  end
  
  def encrypt_password
    if password.present?
      self.password_hash = Password.create(password)
    end
  end

Obsurveyor
Jan 10, 2003

Nolgthorn posted:

I don't know if you saw this or not but there is a brand new railscast on this topic. It's pretty simple to do and hasn't changed very much since the last time.

http://railscasts.com/episodes/250-authentication-from-scratch
Thanks, I pretty much figured it out on my own already but I would not mind seeing someone else implement it too.

I have read many different explanations of salting hashes making passwords more difficult to crack but I still do not understand it. If they have access to the database column for the hashed password, they have access to the random salt column. It does not seem to me like it would take a rocket scientist to modify a dictionary cracker to add the known salt to the dictionary word, hash it and compare. Every description implies the salt is more secret than the hash, but every implementation stores them side-by-side. It feels more like obfuscation to me. I am talking about md5 here, not BCrypt that is now being used. What am I missing here?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Brilliant question. It is such a complicated one that I'm pretty sure there are still entire courses at universities that teach it alone. There are security career tracks where encryption is like a really big part of why you get paid the $$$.

I strongly recommend reading this if you have the time and are interested about the topic.

http://chargen.matasano.com/chargen/2007/9/7/enough-with-the-rainbow-tables-what-you-need-to-know-about-s.html

The whole thing with salting started out as a method for deterring one kind of attack a long time ago. It has become standard since then and Bcrypt will actually handle all of that for you. The article talks to you a little bit about that and tells you about worse threats.

I agree with you about storing the salt in a separate column being worthless. If the attacker has access to the hashed password, then the attacker also has access to the salt for it. The primary idea with regard to hashing passwords is to force the attacker to decrypt each password individually instead of being able to all at once.

A lifetime ago when I was just starting out learning PHP I remember trying my hand at creating authentication. I remember reading documentation that suggested not only using a hash and salt, but also throwing in a few other characters and the date in the middle. That would more or less force the attacker to gain access to the code as well as the database. The problem is that it doesn't do anything to prevent mass-decryption once the attacker finds out what the pattern is, which had been used on every password in the database. So once the attacker knew the pattern it was still as easy as pie to decrypt the full list.

Um. Now I'm leaving my comfort zone with regards to knowledge on this subject so I'll just stop.

Obsurveyor
Jan 10, 2003

Nolgthorn posted:

I strongly recommend reading this if you have the time and are interested about the topic.
Thanks, great read, exactly what I needed. I came to same conclusion a long time ago, that md5 was pretty worthless, salt or no. I still used it but it felt like I was just obfuscating, not really securing, the passwords.

quote:

A lifetime ago when I was just starting out learning PHP I remember trying my hand at creating authentication. I remember reading documentation that suggested not only using a hash and salt, but also throwing in a few other characters and the date in the middle. That would more or less force the attacker to gain access to the code as well as the database. The problem is that it doesn't do anything to prevent mass-decryption once the attacker finds out what the pattern is, which had been used on every password in the database. So once the attacker knew the pattern it was still as easy as pie to decrypt the full list.
I must have read the same thing years ago as well because that feels very familiar.

shehackedyou
Aug 14, 2004

it is never too late to give up your prejudices
Hello, I am having an issue looping through several groups of radio buttons.

So my goal is to loop through and list several groups of shipping options for various products. First I loop through the number of items which need to be shipped alone, then I loop through the shipping rates. What I want is each group to be able to have 1 selection and pass along the params for use in the controller. I need the ability to iterate or count the ss_ship_info so that each name/value will be different params. I have tried both 'ss_ship_info[@counter]' and 'ss_ship_info'[@counter] (this one has really unexpected results, if I have 3 items. The first two act like a single group but the third seems to be an individual group.) Does anyone know a solution for my problem or at the very least could point me in the direction of a guide relating to the subject?

code:
<% @sscount.times do %>  #First Loop 
   <% for rate in @ups_ss_rates[@counter] %> # Second Loop 
      <label> 
         <%= radio_button_tag('ss_ship_info[]'[@counter], rate[0]) %> 
         <%= rate[0] %> - <span class="money"><b><%= sub_number_to_currency((rate[1])) %></b></span> 
      </label> 
    <% end %> 
   <% @counter += 1 %> 
<% end %> 
Edit: I think I figured it out by understanding how to put variables inside of a string.

Edit2: 'ss_ship_info_#{@counter}' doesn't seem to work either =\

Edit3: This bit of code did the trick, it allows me to loop through loops of radio buttons and iterating each group so they are separate parameters. Maybe this will help someone out some day.

code:
<%= radio_button_tag("ss_ship_info_" + @counter.to_s, rate[0]) %>

shehackedyou fucked around with this message at 08:35 on Jan 28, 2011

moctopus
Nov 28, 2005

I started to gently caress around with mongoid and mongodb just for fun, but I've hit a problem early on...

This is a post I made in the mongoid Google Group.


quote:

Hello,

I am having some trouble with a rails project using mongoid.

The problem is when creating/editing a new post.

I would like to select a topic/category for post (entertainment/news/
misc).

At first I tried the method in railscast 238 (near the end) using a
key value

http://railscasts.com/episodes/238-mongoid

But I kept getting a BSON ObjectID error. While searching for a
solution I found topics discussing it, but the fix mentioned is
already in the version of mongoid I'm using.

So I switched things up. I have no idea if this is good practice or
not, but I ran out of ideas. Instead of the railscast method, I used
the code below. However, I get this error...

"undefined method `metadata' for "4d4165b3fcf1ee14e0000049":String"

post model

code:
class Post
  include Mongoid::Document
  field :link
  field :title
  field :synopsis
  field :added_on, :type => Date

  validates_presence_of :link

  embeds_many :replies
  embeds_one :topic
end
topic model

code:
class Topic
  include Mongoid::Document
  field :category, :type => String

  embedded_in :post, :inverse_of => :topics
end
_form.html.erb

code:
        <div class="field">
                <%= f.label :topic_id %>
                <%= f.collection_select :topic, Topic.all, :id, :category, :prompt => "Select a Topic" %>
        </div>
Gemfile information...

gem "mongoid", "2.0.0.rc.6"
gem "bson_ext", "~> 1.2"

Anything stick out?

I got a response...

quote:

> _form.html.erb
> <div class="field">
> <%= f.label :topic_id %>
> <%= f.collection_select :topic, Topic.all, :id, :category, :prompt
> => "Select a Topic" %>
> </div>

Since Topic is embedded in Post, you can't search for topics directly. Thus,
Topic.all , Topic.find , Topic.where , etc don't work. To find a topic, you
need to go through its parent. In this case, a post. Eg:
Post.where 'topic.category' => 'MongoDB'

To set the attributes of a nested topic, the attributes need to be in a
post's "topic_attributes" attribute. IE:
Post.create! :link => '...', :topic_attributes => {:category => 'MongoDB'}

If Post embeds many Topics, then the attribute would be "topics_attributes"
(the word "topic" has been pluralized).

IIRC, the Mongoid release candidates automatically accept nested attributes
for embedded documents. If you're not using an RC, you'll need to add this
to your Post model:
accepts_nested_attributes_for :topic

I don't understand where this code goes.

Is this the right way to go about doing this?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
He/she's saying you cannot do Topic.all, because Topic isn't it's own document. It is only being embedded in other things.

If you were to look at your database you would find a "posts" document and within each post there are many replies and one topic, actually embedded in the post. Not referencing a topic mind you but they're really in there.

So there isn't any way to look up Topic.all, you want to use references and referenced_in. That way the post will only reference a topic and not actually contain the topic.

moctopus
Nov 28, 2005

I understand what he's saying and it makes perfect sense.

I just do not know where in the code to put the changes.

Ethereal
Mar 8, 2003

Nolgthorn posted:

The whole thing with salting started out as a method for deterring one kind of attack a long time ago. It has become standard since then and Bcrypt will actually handle all of that for you. The article talks to you a little bit about that and tells you about worse threats.

I agree with you about storing the salt in a separate column being worthless. If the attacker has access to the hashed password, then the attacker also has access to the salt for it. The primary idea with regard to hashing passwords is to force the attacker to decrypt each password individually instead of being able to all at once.

Now a days, there are what's called "rainbow tables" that you can download that have a precomputed list of password combinations up to certain character lengths. This makes finding the password trivial for unsalted hash values. The time it takes to make a rainbow table is rather long given how complex the function is as well as the number of permutations of passwords.

Adding a salt means you have to brute force every password. Having a different salt per password means this calculation must be done for every password. Storing the salt is not useless at all, but in all seriousness you have a much bigger problem with data security if people can access all of your passwords in a database.

You can also nearly double the amount of time it takes by hashing the password again with a second salt. I wouldn't do this because if a deterministic way to find a collision is found, having two sources of data can only help an attacker.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Ethereal posted:

Now a days, there are what's called "rainbow tables" that you can download that have a precomputed list of password combinations up to certain character lengths. This makes finding the password trivial for unsalted hash values. The time it takes to make a rainbow table is rather long given how complex the function is as well as the number of permutations of passwords.

Adding a salt means you have to brute force every password. Having a different salt per password means this calculation must be done for every password. Storing the salt is not useless at all, but in all seriousness you have a much bigger problem with data security if people can access all of your passwords in a database.

You can also nearly double the amount of time it takes by hashing the password again with a second salt. I wouldn't do this because if a deterministic way to find a collision is found, having two sources of data can only help an attacker.

But I was merely stating that storing the salt in a separate column is worthless, not that salting is worthless altogether. Salting however, is handled automatically now by Bcrypt and it's all stored nice and cozy in the same column. I hope you don't take offence but rainbow tables are from like 40 years ago grandpa.

:corsair:

Bcrypt also automatically supplies a method for doubling or whatever-ing the time it would take to decrypt each password. It's all baked in there so there is certainly no need to double or triple salt anymore.

You may have misread my posts on the subject.

8ender
Sep 24, 2003

clown is watching you sleep
I just want to bear out my shame for everyone here so that everyone knows to be real careful with syntax. Whats wrong with this line in my model?

code:
validates_length_of :card_verification, :in => 1..3, :unless => Proc.new { |account| account.billing_type = "yearly_invoiced" }
:downs: Why is it always storing yearly invoiced even when I pick a credit card?

Anveo
Mar 23, 2002

8ender posted:

code:
validates_length_of :card_verification, :in => 1..3, :unless => Proc.new { |account| account.billing_type = "yearly_invoiced" }

I always do:

code:
validates_length_of :card_verification, :in => 1..3, :unless => Proc.new { |account| "yearly_invoiced" == account.billing_type }
to easily catch similar errors. That goes for basically any language when doing equality checks.

rugbert
Mar 26, 2003
yea, fuck you
Ok, I have an association where a User has_man blogs. It works, has the foreign key blah blah blah.

What Im trying to do is filter blog posts based on the user who made it. And while I have it working, it only filters based on user_id (which is on the BlogPost model) but I want to filter based on username which is on the User model.

Right now, this is what I have to make it work:
code:
Model:
@blogs = BlogPost.where(:user_id=> params[:user_id]).all

Route
match "author/:user_id"=>"index#author", :as => :author
But I want the author's name to show up in the url so I was thinking of doing:
code:
Model:
@blogs = User.blog_posts.where(:username=> params[:user_id]).all

Route
match "author/:username"=>"index#author", :as => :author
I dont know if RoR is going to grab the right :username based on the user_id but I cant even get that far. My view is telling me that "blog_posts" is undefined. But thats how I set up my controller in the admin section to get all user's blog posts.

NotShadowStar
Sep 20, 2000
First, params[:username], as you defined in the route.

Second, you want

code:
u = User.where(:username => params[:username).first
@posts = Post.where(:user_id => u.id).all
You can get more clever and concise with the syntax, but this is clear and easy to understand.

rugbert
Mar 26, 2003
yea, fuck you

NotShadowStar posted:

First, params[:username], as you defined in the route.

Second, you want

code:
u = User.where(:username => params[:username).first
@posts = Post.where(:user_id => u.id).all
You can get more clever and concise with the syntax, but this is clear and easy to understand.

ohhhh cool gotcha! thanks!

So Im starting to learn about helpers and I found a small code snippet that produces a list of items based on the collection thats passed into it but I dont know how to html_safe it. the OL tags are fine, but everything inside it isnt and I dont know why.

Heres my helper:
code:
  def list(stuff, &block)
    content_tag(:ol, stuff.map{ |list| content_tag(:li, yield(list)) })    
  end
and here is my view:

code:
<%= list(@categories){ |c| link_to c.name, blog_category_path(c.name) } %>
Almost done with my first rails project!

skidooer
Aug 6, 2001

rugbert posted:

I dont know how to html_safe it.
code:
content_tag(:ol, stuff.map{ |list| content_tag(:li, yield(list)) }.join.html_safe)

Triggerle
Jun 3, 2001
So my first application is coming along nicely and now that things are working I would like to add Ajax functionality to some of my views. After doing some research it seems jquery is what I want. So I installed gem jquery-rails, included it in my Gemfile and ran bundle install but it doesn't seem to do anything? In my public/javascripts folder I have
code:
application.js
controls.js
dragdrop.js
effects.js
prototype.js
rails.js
All are timestamped from when I created the application and looking into rails.js suggests that it is part of prototype.

Also I'm getting mixed advice in the various tutorial I read. Should I bother with the gem at all or should I just link to Google's library?

NotShadowStar
Sep 20, 2000
Yes use jquery-rails because it changes the internal generators from Prototype to jQuery. jquery-rails also loads jQuery when you do javascript_include_tag :defaults. You also need to do 'rake generate jquery:install' to change the internal defaults and remove Prototype.

I'm also assuming you're doing Rails 3. Javascript is much, much nicer in general in Rails 3 than 2. Rails 2 dumps automatically generated JS directly on elements everywhere. Rails 3 changes it by adding specific classes and IDs to elements and uses Javascript to target those elements.

rugbert
Mar 26, 2003
yea, fuck you

skidooer posted:

code:
content_tag(:ol, stuff.map{ |list| content_tag(:li, yield(list)) }.join.html_safe)

Oh cool thanks. Yea I was confused because I thought content_tag made everything in it html safe. And adding .html_safe wasnt doing anything.

NotShadowStar
Sep 20, 2000
Any string when calling html_safe? on it is false unless something explicitly marks it as html_safe

http://asciicasts.com/episodes/204-xss-protection-in-rails-3

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Hello. I am rolling my own pagination. Not using will_paginate has thrust me into a state of uncertainty.

Each of the users in my application are seeing different objects on each page and the objects that they see may change from page to page. So it isn't really possible to paginate reliably using a page number, instead I am using starting at and ending at times.

If a starting time is specified, I will get x number of objects to display which were posted after that date. If a ending time is specified instead, I will get x number of objects to display which were posted immediately before that date. I also need to reliably know the posting date of the object which follows the last object in my collection as well as whether or not there is a post before the first object in my collection.

It's much different from what will_paginate offers is what I'm saying.

Can I implement a pagination method onto all my database objects using the lib folder, what is the process for adding a method there?

NotShadowStar
Sep 20, 2000
You likely want to roll it as a Module, and include awesome_pagination in the models you want to do it with.

Adbot
ADBOT LOVES YOU

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
That would certainly be the easier way to do it... but how does will_paginate get around this? I've been reading will_paginate and don't think I've been able to decipher very much of it.

I could just use a module I include I guess.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply