ruby-on-rails-3

Rails 3.1, internalization of values from a habtm relationship?

[亡魂溺海] 提交于 2020-01-06 20:06:39
问题 I got a Event model that HABTM Categories. The relationship works fine and I can insert/retrieve values from Categories with no problem. My questions is, is there a way to interzationalize(I18n) the values of this categories. Category Model class Category < ActiveRecord::Base has_and_belongs_to_many :events end Event Model class Event < ActiveRecord::Base .... has_and_belongs_to_many :categories .... _form.html.haml (for events) - Category.all.each do |category| .field = check_box_tag

Tempory file share

荒凉一梦 提交于 2020-01-06 19:48:41
问题 Hi i am building an ruby on rails application.I wants to share an attachment for a maximum of one hour only,thereafter that particular link must be deactivated. is that possible to achieve this without doing any CRON job ? My requirement is user can upload attachments and they can share the encrypted URL.the maximum validity of that URL will be one hour. I want to know that whether it is possible by without creating any CRON job ? if yes please help me ? 回答1: you can use application

storing complex records in rails database with form_tag

点点圈 提交于 2020-01-06 19:47:11
问题 I'm trying to save records in a database. Many of the column values will be taken from a http request to an api. I have a text field and some check boxes along with the session_id in the form which will be persisted. this is posted from another controller ( form_tag('results#store') )to an action called store in the results controller. Store action: def store query = query_preprocesser(params[:query]) # this is in a helper ## example of resArray ## #resArray = [[{:engine => "bing, :results =>

Using js.rjs to render inline content

懵懂的女人 提交于 2020-01-06 19:34:12
问题 I am trying to improve my knowledge of Rails. I was trying to use js.rjs in a simple code. Here's the view: <div style="background: #000080; font-weight: bold; margin-left: 30px"><p>This should Remain Same</p></div> <div id="noid"> <%=link_to 'Click',:action=>:say_when , :remote => true %> and I will look it up. </div> And here's the controller: class DemoController < ApplicationController def say_when respond_to do |format| format.js end end end And I have views/Say_when.js.rjs as follows:

Ruby on Rails - Show field from has_many table

吃可爱长大的小学妹 提交于 2020-01-06 19:33:19
问题 I've got two tables: Ships and Voyages. A ship can have many voyages, but a voyage may only have one ship. In RoR the ship model has a has_many :voyages and the Voyage model is set to belongs_to: ship I can display all of the fields from the ship table in the view without any problems using code similar to this: <%= @ship_data.id %> I'm now trying to show a piece of information from the voyage table in the view. If I do: <%= @ship_data.voyages %> I'm able to pull up the ActiveRecord entry i.e

Session variable not persisting after switch

僤鯓⒐⒋嵵緔 提交于 2020-01-06 19:32:39
问题 I have tried to implement a switch between a basic and advanced viewing mode on a show page, essentially switching a basic/advanced div on/off through a link. In the controller I store the viewing-mode in a session variable (using a similar approach to http://railscasts.com/episodes/199-mobile-devices). Problem: the toggling works fine changing the viewing mode, but as soon as I click on a link to a different show-page in the non-default viewing-mode it takes me back to the default-mode, why

How to select record by distinct column in Rails3?

[亡魂溺海] 提交于 2020-01-06 18:55:13
问题 There is one model named Book, I want to get all books, but all results have distinct column named 'author', how to do this ? thanks! 回答1: May be by: Book.select("DISTINCT(author)") for more read this: Active Record Query Interface Edit You can try: find_by_sql as Book.find_by_sql("select * from books group by author") 来源: https://stackoverflow.com/questions/5701911/how-to-select-record-by-distinct-column-in-rails3

Rails - Update attributes using rake task. Need help troubleshooting model method code

心已入冬 提交于 2020-01-06 18:08:22
问题 I am trying to use a rake task that will run every night (using Heroku Scheduler) and update some attributes if some certain criteria is met. A little logic about the application: The application allows users to "take the challenge" and read a book a week over the course of a year. It's pretty simple: users sign up, create the first book that they will read for their first week, then can enter what they're going to read next week. After they've "queued" up next week's book, that form is then

How do I update & display a current user's tags, tagged with acts_as_taggable_on?

巧了我就是萌 提交于 2020-01-06 17:15:30
问题 I'm not sure how to display tags in my view that belong to a user logged in with Omniauth. A page in the view loads a random photos and tags associated to it (via a form that can be updated from that page). It works, but when I log in with Facebook account A, it will show exactly the same tags as if I log in with Facebook account B. Getting the whiny nil error with this below Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id The view is: <%=

How do I update & display a current user's tags, tagged with acts_as_taggable_on?

元气小坏坏 提交于 2020-01-06 17:15:14
问题 I'm not sure how to display tags in my view that belong to a user logged in with Omniauth. A page in the view loads a random photos and tags associated to it (via a form that can be updated from that page). It works, but when I log in with Facebook account A, it will show exactly the same tags as if I log in with Facebook account B. Getting the whiny nil error with this below Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id The view is: <%=