rails // format.js or format.json, or both ?
might be obvious, but still i'm lacking here of basic knowledge. so inside controllers, can both be used, or is it always javascript, so both are the same ? ...
might be obvious, but still i'm lacking here of basic knowledge. so inside controllers, can both be used, or is it always javascript, so both are the same ? ...
Hello, A user can only edit its own post, so I use the following to check if a user can enter the edit form: def edit @post = Load.find(:first, :conditions => { :user_id => session[:user_id], :id => params[:id]}) rescue ActiveRecord::RecordNotFound flash[:notice] = "Wrong post it" redirect_to :action => 'index' end ...
I have a simple web app with users and posts. I have an index controller and view that shows a list of the posts in the database. With the list, it shows a "Show" link which links to the specific post. I am trying to replicate that for users but something is going wrong. I have an index view that shows all the users in the database and ...
probably best if i first just write my code down. i have: <li class="sorted" id='<%= domid %>'> <%= horse.name %> </li> <%= draggable_element(domid, :ghosting=>true) %> after the drop on some "box" the draggable element with name = horse.name stays on it. i want to delete it(the name). i was trying different things. supposedly i ...
Assumptions: A contact has many notes. A contact has the ID of 1. A note belongs to a user. A user has the field name, "name". Using the prawn gem and prawnto plugin, I've noticed the following: In my view (for the PDF): for note in @contact.notes pdf.text "#{note.user.name}" end This is ideally how I'd like to display the PDF,...
Hi guys, I'm using rspec to test a code that may fail depending on the change of a site structure (the external influence I mentioned). I would like to write an example that involves "should raise an error" but I'm not sure if rspec is the right tool to test code in such situations. Could someone point me in some direction? Thanks in a...
I've read through countless tutorials and I keep coming up short. Here's what I've got: -- I'm running RubyMine on my Windows desktop -- I've installed Git on my WebFaction hosting account per their instructions -- Git appears to be working fine on both machines Here's what I'm doing: 1. On server: a. mkdir project b...
Hey guys, I wanted to write something that could receive text messages and respond with data queried information from my database. I have been playing around with this and discovered that you can send/receive text messages to email addresses. What would I need to write to have the a program to constantly check for new messages to an ...
I've got a batch of a 100k or so records that I'm importing to a Rails app. There's a date in each row formatted like the following: 03/17/81 However, when I try to just assign it to a date field, it gets converted as follows: ruby-1.8.7-p174 > "03/17/81".to_date => Sat, 17 Mar 0081 Ultimately I would like the format to result in ...
I am converting my ERB template to a HAML template. <p> Welcome to <span><%= name1 %> </span>, <span> <%= name2 %></span> and <span><%= name3 %></span>. </p> This is what I have come up with %p Welcome to %span= name1 , %span= name2 and %span= name3 . I have a feeling that there is much more elegant way to do this...
Here's a common pattern in my controller actions: respond_to do |format| format.html {} format.js { render :layout => false } end I.e., if the request is non-AJAX, I'll send the HTML content in a layout on a brand new page. If the request is AJAX, I'll send down the same content, but without a layout (so that it can be inser...
I have a rails class that serializes one attribute. class Statistic < ActiveRecord::Base serialize :userlist end When a statistic object is loaded and it's userlist changed from a String to an Array userlist always gets serialized back into a String. The framework seems to remember and deserialize :userlist into a String ...
We have this string: "according to posts #4,#5 and #6 the word..." I want to convert the "#4", "#5" and the "#6" to links, using the link_to helper (the numbers are ids of a Model) How can I do this? Is this difficult? Thank you in advance. ...
I have a couple of models in a Rails app. Let's say it's Products and Sales. A product has many sales, and a sale belongs to a product. What I am looking to do is get a list of all products (possibly with conditions) and next to each product provide a count of the number of sales, similar to: Product 1 (10) Product 2 (22) Whilst...
Paperclip is a great upload plugin for Rails. Storing uploads on the local filesystem or Amazon S3 seems to work well. I'd just assume store files on the localhost, but the use of S3 is required for this app as it will be hosted on Heroku. How would I go about getting all of my uploads/attachments from S3 in a single zipped download? G...
Hi All, How do I use both include and join in a named scope? Post is polymorphic class Post has_many :approved_comments, :class_name => 'Comment' end class Comment belongs_to :post end Comment.find(:all, :joins => :post, :conditions => ["post.approved = ? ", true], :include => :post) This does not wo...
Hi, I have a complex form in Ruby on Rails 2.3.5, here's the structure for it: Artist - Name - Albums -Songs - Photos Each artist can albums and several photos. For each album, there are several songs. I want to create a 3 step process. - Create Artist - Create Album (will have option to create multiple songs) - Create...
I'm trying to save some lookup table data out to a YAML file so that later when I need to set up my app on a different machine I can load the data in as seed data. The data is stuff like select options, and it's pretty much set, so no worries about the live data changing between serializing and deserializing. I have output the data lik...
Lets say I have a rails application in which code is pasted into the content text box like the following. Pasted Code Person name Person name Person name Person name It is put into the database with the proper new lines after each line according to my server log. What I want to do is in the show action I want to output this text a...
Let's say I had an app that was an address book. I'd like to have a page dedicated to a "dashboard". On this page, I'd like to have a running list of the events that happen within the app itself. Event examples could be: A user adds a contact. A user deletes a contact. A user updates a contact. What would be the best way to create...