06 September 2010

The Ruby Reflector

Topic

POST

  Source Favicon
By Claudio of DevInterface Blog 7 hours ago.
Email

@ posts = Post. all

end

def new

@ post = Post. new

end

def show

@ post = Post. find ( params [ :id ]

end

def edit

@ post = Post. find ( params [ :id ]

end

def create

@ post = Post. create ( params [ :post ]

end

def update

@ post = Post. update ( params [ :post ]

end

def destroy

@ post = Post. find ( params [ :id ]

@ post . destroy

end

end

Then if we want the calls to some methods (eg show and index) can not be traced we can simply …

blog.devinterface.com Read
  Source Favicon
By anup.narkhede of for i in infinity 1 day ago.
Email

Person.add(new Post({id: 1, name: "bean"})) => Console: added bean

Observe remove event on the class collection: Person.observeRemove(function(instance){ console.log('removed ' + instance.get('name')); }); var post = new Person({id: 1, name: "bean"}); Person.add(person);

Person.remove(person.get('id')) => Console: removed bean

Validations

MooModel provides a full validation framework. The following example shows …

anup.info Read
  Source Favicon
By Jason of Jason Seifer 14 days ago.
Email

…Update documentation on autosave .

Several performance improvements mostly by tenderlove .

Tons of deprecations.

Require rdoc version 2.5.10

Require rack-mount 0.6.12

Delicious Digg This Post Facebook Reddit This Post

No related posts.

jasonseifer.com Read
  Source Favicon
By Iain Hecker of Adventures with Ruby 14 days ago.
Email

…:xml def index @ posts = Filter :: Posts .new(params[ :filter ]).all respond_with @ posts end end

As you can see, this places the logic of filtering in its proper place. It's not part of the model, since it's not part of initializing objects, or behavior of individual post objects. It's a separate service, doing something with something else.

These services are incredibly easy to make. Just think about the objects it's trying to handle. These are probably the arguments …

iain.nl Read
  Source Favicon
By Jason of Jason Seifer 1 month ago.
Email

This has been around for a little while now, but Genius Pool now has Twitter integration when a new job is posted. Check it out and post a job.

Delicious Digg This Post Facebook Reddit This Post

jasonseifer.com Read
  Source Favicon
By Claudio of DevInterface Blog 1 month ago.
Email

@ post = Post. new ( params [ :post ] )

@ post . user = current user

@ post . expiring date = Time . now + 7 . day

@ post . save

end

end

Let us now see how to define a proper method (the Factory Method) of creating the news in the model so, once again, we simplify the controller

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

class Post < ActiveRecord:Base

def publish_new_post ( params, user )

post = Self

blog.devinterface.com Read
  Source Favicon
Email

…and that we handle the result accordingly. context "updating a post" do setup do @ post = Factory :post Post.stubs(:find => @ post) end

context "when the update is successful" do setup { @post.stubs(:update_attributes => true) }

should set_the_flash.to(/updated/) should redirect_to(posts_path) end

context "when the update is unsuccessful" do setup { @post.stubs(:update_attributes => false) }

should render_template(:edit) …

robots.thoughtbot.com Read
  Source Favicon
By techarch of The "Tech. Arch." 3 months ago.
Email

to instantiate a new Post and render the add view method: # GET /posts/new def new require_login! @ user = User.find @state.user_id @ post = Post.new render :add end

Then finally we will need a route to edit an existing blog entry via HTML, so let's add an edit action method

to lookup an existing Post by id and render it using the edit view method: # GET /posts/1/edit def edit(post_id) require_login! @ …

blog.monnet-usa.com Read
  Source Favicon
By dc.rec1 of Diego Carrion 3 months ago.
Email

…Resource public class ShoppingCartController { ... } public class ProductsController { @ Post @ Path ( "/products" ) public void add ( Product product ) { ... } ... }

In the Ruby language, two annotations that are very used are the methods protected and private , which without arguments restrict the visibility of the methods defined below them:

class User def jump; end ; protected def eat; end ; def flirt; end ; privat …

diegocarrion.com Read
  Source Favicon
By Peter Cooper of Ruby Inside 4 months ago.
Email

Want To Post A Job?

If you want Ruby Inside and Rails Inside to promote your own Ruby/Rails career openings, you can Post A Job. $ 249 for 60 days of exposure with a link on all Ruby Inside and Rails Inside pages, exposure through Simply Hired, and (usually) inclusion on a post like this that goes out to all 23,000 subscribers. Most ads get 1-2,000 direct views during their run (and linked from about 280,000 pageviews on our sites in all).

rubyinside.com Read