ruby-on-rails

avoid loop in returning the same attribute in the definition of the method

Hello all, I have a simple article model with a predefined_title attribute and a user_defined_title attribute All I want is to make a virtual attribute that shows the user_defined_title if available and predefined_title if not But I thought what a waste to add another virtual attribute, if I could only do something like this def user_...

Rails model constants with hash

I have added some constants to a model say MyModel.rb as shown below. MY_CONST = { :foo =>"Some Name for Foo", :bar =>"Some Name for Bar" } Also I have saved string foo as the column value in a table record. @m = MyModel.find(1) @m.column_name #=> foo Now in my view I need to show "Some Name for Foo" as the output for @m.colu...

Rails - Calling a POST function from server

Hi folks, I need to access a controller level action from another action. This is accessed by the view (so need authenticity token) def post_message #creates the message #normally accessed via webform with authenticity token end def post_via_email #my virtual mailserver calls this method when it receives an email #i need to cal...

How to Show/Hide a block of text with ruby on rails based on a button click or link click

I'm new to ruby on rails and i'm trying to figure out how to hide/show a block of text based on a clicking a button or a link. I followed the example in this link: http://www.davidthomas.net.au/2009/09/ruby-on-rails-howto-showhide-div/comment-page-1/#comment-441 However, there are three problems I've experienced I'm not sure how to ...

how to check the current status of server(up/down) from my rails application

how to check the current status of server(up/down) from my rails application . If server become down,and many users are logined, I need to perform some actions. ...

How does one make models in Rails?

I've gone over the tutorial, used the scaffold command to make a model, etc. I noticed that it mentioned more experienced programmers would probably create all their models from scratch... What is the "appropriate" way to do so? If it's a simple answer and I'm just Googlin' the wrong keywords, I apologize in advance. ...

How can I force Rails to load all models?

Rails does model loading on demand. For a rake task that I'm writing, I need to be able to iterate over all ActiveRecord::Base instances (which is possible with ActiveRecord::Base.send(:subclasses)). However, for the above to work, they have to already be loaded. Anyone know of a way to force all models to load? Ideally I'd like to n...

Auto testing a user's age fails every year

I want to test the age of a user of my Rails application using cucumber. The feature definition look somewhat like following. Scenario: Successful calculation of age Given I set my date of birth to "1987-07-15" Then my age should be "22" Above feature definition will fail every year since the age of user will increase by one each ...

Efficient way to implement this ActiveRecord Query

Hi I am using MySQL database and I have a datetime field inside it. In my rails application I have to fire a Query similar to the following, MyTable.all(:conditions=>{my_date.to_date=>"2010-07-14"}) The my_date field is of datatype datetime. I should omit the time and should directly compare it with a date (but I am encountering an e...

:limit number of rows found in a collect (has_many association)

Category has_many :products has_many :deals, :through => :products Product has_many :deals I want to display a limited number of deals on a category page. In categories_helper.rb: def deals @category.products.collect { |c| c.deals}.flatten end In the show.html.erb (Category): <% for deal in deals %> <%= deal.name %> <% en...

Problem with default_scope in Rails 3? NoMethodError

I am experiencing a weird bug after adding this to my Alternative-model: default_scope order(:number) On the first page refresh, everything works fine. On subsequent refreshes, I get NoMethodError in Pages#show undefined method `written?' for #<Alternative:0x10455c558> Alternative most assuredly has the written? method. I am runni...

handing over a param from a rails form tag

Hi there, I'm using a form tag to implement a search text_field. <% form_tag catalogues_path(:select => params[:select]), :method => "get" do %> The problem is the catalogues_path which should consist the select param. Unfortunately the select param doesn't get handed over in the upper example... The result is the same as if I would...

Are there any php frameworks contain small webserver and rich console tools like RoR/Django?

In Ruby on Rails, I can start my web application, just write in console: script/server. RoR contains small webserver and rich console tools, but I didn`t meet such tools in php frameworks. Are there any php frameworks contain small webserver and rich console tools? ...

MySQL server has gone away: Rails on Passenger (Redmine)

Hello all, I am making use of Redmine a web based software tracking tool, its perfect for my needs. However, I keep coming across this error in my production.log. ActiveRecord::StatementInvalid (Mysql::Error: MySQL server has gone away: SELECT * FROM issue_relations WHERE (issue_relations.issue_from_id = 6) ): app/models/i...

Rails/Activerecord database field timezone

I have a database that is written to by a non-rails application and read from by a rails application. There is a datetime field in the database and the data stored in this field is stored in Eastern Time. In my rails app, I understand I can set the application's timezone in my environment.rb file by doing config.time_zone = 'Eastern Time...

Whats the recommended rails way to access a has many from another has many association

I have a User model which has many books, each book model has many authors, whats the rails best practice way of being able to access all the authors of all the books that the user has linked to it? ...

Getting an unterminated string literal error..I can make it pass, but can't figure out why..

I'm getting an unterminated string literal error in Firebug: Unterminated string literal $(".search_info").html("<div id=\'sear...arm_bg.png?1279054090\" style=\"displ\n This error is being rendered from clicking on a Sort By that toggles 'Most Recent' I have narrowed it down to the 'about_us' text. By removing certain parts of the t...

Can I add the limit the result of object return in Ruby on rails?

For Example, I want to know the User have many posts. So, I can get back post using this : @user.posts but I don't want to get all the posts back. I would like to limite the result, for example, top ten created, or may be sorted by some column. How can I do so? Thank you. ...

How do I show/hide multiple divs (not possible for each to have a unique ID) in a Rails app?

I need to create a 'Reply' button that shows a form for any item in a feed. In other words, it can't be showing/hiding something with a unique div id, because it has to work for any of a (potentially) infinite number of items. If I use code like this: <% @questions.each do |question| %> <%= question.content %> <a href="" onclick="s...

How do I override a Devise 1.1.rc2 controller?

I want to add the option to register with a JSON format and some other specific stuff to my application. I've tried adding my own RegistrationsController controller and then setting my routes to look like this: devise_for :users, :path_names => { :sign_in => 'signin', :sign_out => 'signout', :sign_up => 'signup' } match 'signin', :to =>...