helpermethods

Can Rails Routing Helpers (i.e. mymodel_path(model)) be Used in Models?

Say I have a Rails Model called Thing. Thing has a url attribute that can optionally be set to a URL somewhere on the Internet. In view code, I need logic that does the following: <% if thing.url.blank? %> <%= link_to('Text', thing_path(thing)) %> <% else %> <%= link_to('Text', thing.url) %> <% end %> This conditional logic in the vie...

How to use "count" in rails to show how many projects/tasks user has?

Hello, I defined method 'count' in my tasks controller as: def count @count = current_user.tasks.count end I'm not sure how to show that in my tasks views. Do I just use Tasks count: <% @count %>? How do I get in my view how many tasks the user has? Thanks ...

Problem with returning values from a helper method in Rails

I want to print some objects in a table having 2 rows per object, like this: <tr class="title"> <td>Name</td><td>Price</td> </tr> <tr class="content"> <td>Content</td><td>123</td> </tr> I wrote a helper method in products_helper.rb, based on the answer of this question. def write_products(products) products.map { |prod...

Organizing c# project helper classes

Whats are some best practices for where you should have helper classes in a .NET project? Referring to classes separate from business layer stuff, but presentation and app stuff like appsetting config managers and other code that would sometimes be module specific or sometimes be used throughout the app. ...

Where do I put helper methods for ActionMailer views?

I have a method that takes an array of strings and joins them so they do something like this: >> my_arr => ["A", "B", "C"] >> and_join(my_arr) => "A, B, and C" Which I'd like my mailer to have access to so I can output some information into an email. I can't seem to find a good place to put it and putting it in the application_helper....

How do I write methods that insert rspec examples?

In a bunch of rspec rails unit specifications I do something like: describe Foo do [:bar, :baz].each do |a| it "should have many #{a}" do Foo.should have_many(a) end end end For cleaner code I'd rather do something like: describe Foo do spec_has_many Foo, :bar, :baz end So how do I write a helper method like spe...