ruby-on-rails

How to re-register common javascript events in Rails after an Ajax request

Hello everyone, I'm writing a Rails app which includes ajax functionality using jQuery. I hope you guys could help me out here. For example, in my /public/javascripts/application.js : /* application.js */ ... $('.item-edit').editable('/item/update', { name : $(this).attr('name'), id : $(this).attr('id'), cancel : 'Can...

Sending a tweet using Authlogic-OAuth

Hi, I'm building a Rails application which uses Authlogic for authentication, which I've now set-up to run using the OAuth extension, meaning a user can be created by signing in from Twitter. This stores their OAuth token and OAuth secret, meaning they're accessible, but I was wondering how I would actually go about sending a tweet usin...

Click testing on rails 2.3.10 site works under mod_passenger, selenium tests fail when running under mongrel. Why?

So I'm working on a large rails app that has a bunch of selenium tests. Running a local dev instance of the site (apache w/ mod_passenger) works fine, but when I run the selenium test suite I get a bunch of failures, particularly on re-directs. The HTTP response header comes back poorly formatted. Among other problems the Set-Cookie h...

Can I change my migrations depending on the database adapter? How will it reflects in the schema.rb?

Specifically, I want to add an spatial index in a multi_polygon column. This works nicely in PostgreSQL but not in MySQL, so I was thinking of somthing like: create_table :figures do |t| t.multi_polygon :polygon end add_index :figures, :polygon if database_adapter == :postgresql Is it possible and a good idea? ...

RoR: Storing HTML in a File for Later Use

Hi All, In our application we have different themes and each theme has its own default content in the following structure: ROWS COLUMNS CONTENT HTML DATA 1 CONTENT HTML DATA 2 There could be multiple rows, column and content elements. We need to store this data in a file (manually) and then read & dump it ...

Inviting Users to Events via Facebook API

I'm able to create an event via the Facebook Graph API but I have yet to see a way in which to invite users to that event. My fallback is to simply use the old REST API but sooner or later that will be phased out so I wanted to see if anyone had any suggestions. -- Additional side question: While using the REST API (or possibly even...

i18n on Ruby on Rails, < and > gets replaced by &gt ; &lt ; when not intended

I am creating locale files for internationalization in a rails app, and have a url that I want translated with tags included , for example html.erb <%= t(foo.bar.xxxx) %> yml file foo: bar: xxxx: "xxxx" result &lt ;a href= "/info/index.html"&gt ;xxxx</a&gt ; which breaks my links. I do not have an h on th...

Error restoring postgres database backup

Hi everyone. I've setup a system to automatically download and store a db dump from my Heroku deployed rails app. Everything is working great but when I download the dump and restore it to my local postgres server then try and run my local app off that restored database I get this error ActiveRecord::StatementInvalid in HomeController#i...

Sinatra vs. Rails

I've worked through some of the Sinatra and Rails samples, but I'm having a hard time figuring out which features belong to which technology. What specifically do I gain by using Sinatra/Rails? Is it just ActionPack/ActionView? Correct me if I'm wrong, but I COULD just use Webrick/Mongrel and serve up my .erb files right? And I could us...

Rails InvalidAuthenticityToken with Google Translate

Hi everyone, I'd like my users to be able to use Google Translate with my Rails apps. I have forms and login for the app. I keep getting the Rails InvalidAuthenticityToken when using the app through Google Translate. Any insights on how i can get both to work? I am using Rails 2.5.x. Thank you! PS: To clarify, this the authenticity t...

Copy fixed data into model

Hi all, I'm developing an application in which a Course belongs to a user. I would like to predefine a number of courses, such that a Course's template details are then copied into the users course details. From this initial point each user has a one-to-one mapping with a course. I'd like to know the best place for the static attribut...

Cucumber IDE for feature writing with autocomplete?

Hi, Is there any Eclipse plugin for writing features for cucumber with autocomplete functionality? I guess that would be good to find and reuse steps from other features. Any ideas? ...

ROR + Replace the last character by detecting it using ruby code by another character

Is it possible to detect the last character of string in ruby on rails and replace it by "". Explanation :: Suppose I have string as "demo-" then i have to check its last character, If it is "-" then replace it by "", otherwise no action should be taken. Example - Code :: search_text.downcase! if !search_text.nil? now if seach_text h...

select field, text field and foreign key

Hi everybody, I would like to know which way is the best to resolve my question : I have a form in order to select people via a select field. If the name is missing in the select field, a text field is available to add directly the person's name. - The form in new.html.erb is the format of the new action of the Team controller. - The lis...

Model and controller design approach for polymorphic assocation

Below I have outlined the structure of a polymorphic association. In VacationsController I put some comments inline describing my current issue. However, I wanted to post this to see if my whole approach here is a little off. You can see in business_vacations_controller and staff_vacations_controller that I've had to make 'getters' for ...

Rails Nested Form - Filter by Current User, Lesson-Questions-Answers-Users

Hi All, I have a nested form that is based on the following model -- A lesson has many questions, each question has many answers, and answers belong to users. I am developing a nested form, so that a new user can review the questions and post answers. If a user has entered answers in the past, I want those to show up; otherwise show ...

Clean up task when combining multiple tasks in Rake

I have a build task in rake defined with the following dependencies: desc 'Builds the App' task :rebuild_dev => ["solr:start", "db:drop", "db:create", "db:migrate", "spec", "solr:stop"] The first task "solr:start" starts the Solr Indexing server. Now, if the build fails (may be in spec tests fail), the "solr:stop" task is not executed...

Rails - Conditional Form Elements?

Hello, I have the following in a form: <%= f.hidden_field (:project_id, :value => @project.id) %> This form partial sometimes contains a @project. Sometimes it does not. This is the nature of the app. But I want to use one partial because it's a big form. Problem here is if it does not contain @project, the page ERRORS.... How can I...

Authlogic, rails3_acts_as_paranoid and validates_uniqueness_of :login + default_scope(:conditions => {:active => true})

I want to be able to create multiple user accounts with the same login (because of the case a user deletes his account... and then sign up with the same login). I am using authlogic and rails3_acts_as_paranoid. But there is a problem: Authlogic validates the uniqueness of the login field - and IGNORES the default_scope(:conditions => {:...

Rails 3 - controller Conditional?

Hello, tricky problem. I have a controller that is: def create . . @project = Project.find(params[:project] @Log = Logs.create(params[:action]).merge(:project_id => @project.id)) ... end The issue hereis that sometimes when DEF CREATE, I'll have a project and I want to record that. Other times I won't and that's perfectly fine, I st...