Rails-like routing framework - ruby-on-rails

is there any rails-like routing I can use in my non-rails app? I really like the way of defining url matching. Something like:
if matcher.match("/myapp/cart/:id/create")
puts matcher[:id]
end
Something similar. I would prefer simple solution to that. Maybe a snippet or reference to some code that can be used. Or a library. Thanks

You can do it with rack also
https://github.com/mynyml/simple_router

Sounds like Sinatra may be perfect for you:
http://www.sinatrarb.com/

If you just want sinatra like routes inside a rails app you may want to try sinatrify
astaire also seems to offer the same functionality but is not compatible with rails >= 3.2 with which i tried to use it.

Related

How do I get the correct current_MODEL from devise in a Rails engine?

I'm writing an engine and I'd like it to integrate well with devise, but not necessarily be dependent on it. Specifically, I'd like to be able to reference the current_MODEL (default: current_user). Is there a generic method I can use in my engine's controllers?
Looks like Ryan Bigg answered my question already!
http://ryanbigg.com/2012/03/engines-and-authentication/

Embed Blog in Ruby on Rails

I have a Ruby on Rails application and want to include a blog inside the application.
I was wondering what's the best way to do that. I don't want to have a link to an external blog. I want the blog integrated in my application. Also i don't have the time to programm the blog functionality. I want to use existing solutions.
What's the best way to accomplish that? Any recommendations? What are the best solutions?
The best way to include one application within another is by using engines. This might help you Ruby on Rails 3.1 Blog Engines
Perhaps Typo would address your needs installed as a Rails Engine.
Since nobody has done it so far I need to mention here that the spirit of Rails is to make everything friendly enough so that you can code your own.
It's a bit more work but then your blog module fits right in with the rest of the app.

Other Rails templates types

Erb is the default template type in Rails and I read about Haml.
What other types exist and can be used in Rails?
Thanks.
Take a look at the Ruby Toolbox.
I only know Mustache, Liquid and Markaby of those above, but seems there are pretty many other alternatives.
Rails 3 uses Erubis by default.
You may also want to take a look at slim, which is elegant in a HAML fashion but apparently faster! https://github.com/stonean/slim

Ruby on Rails customer-facing formbuilder?

I have a customer that wants to build their own questionnaires. Something like WuFoo (www.wufoo.com) but more secure and contained within the app.
I've looked at Smerf (http://github.com/springbok/smerf) which provides the yaml-to-form conversion, but I'd like something the user can use to create their own forms.
I would look at using active_scaffold. The main version has not been updated for Rails 3, but a fork at the location below has. I think it would work well for your purpose, you just need a way to grab the data and feed it in. Here is a demo of what it looks like when it is running:
https://github.com/vhochstein/active_scaffold
Here is a demo at the top of the page:
http://demo.activescaffold.com/roles
You could always embed Google Forms. Might be easier than reinventing the wheel. Unless you have some specific use case this doesn't cover?
If you are not adverse to going the Javascript route the then you might consider one of the many framework plugins like the JQuery Form Builder. From a usability perspective it seems to me that any good solution is going to involve some Javascript. There should be no reason why this approach wouldn't integrate well into a Rails backend
You might want to check out this one. Dynamic Forms
I too am looking for something very similar. What solution did you come up with?

Simplest way to send mail with Ruby on Rails

What is the simplest way to send mail using Ruby on Rails? Is there a way to send mail directly via ruby and skip all the rails models and complexity, just like php's mail() function?
Thanks for your help.
The simplest way in plain old ruby is to use net/smtp. However rails has it's own built in mailing facilities, because sending mail is something that is pretty common. The best way to do it in rails, is to use a Mailer model
Make sure you replace all the example.com's with real values:
require 'net/smtp'
Net::SMTP.start('smtp.example.com', 25) do |smtp|
smtp.send_message "Subject: testing from ruby", 'from-address#example.com', ['to-address1#example.com', 'to-address2#example.com']
end
There's also TMail.
Another excellent solution is a gem called pony. It is exactly like php's mail() function. Simply and easy.
yes check out the ruby docs...http://ruby-doc.org/stdlib/
the package you want to look at is net/smtp
there is also
http://www.rfc20.org/rubymail/(ruby mail)
which is popular and make it a little easier
I'm concerned that if you don't want to use ActionMailer that maybe you just don't get rails. ActionMailer makes sending email with good templating and the like very very easy, you really should look into it.

Resources