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...
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
...
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...
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.
...
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....
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...