Search Results

Search found 9437 results on 378 pages for 'rails newbie'.

Page 112/378 | < Previous Page | 108 109 110 111 112 113 114 115 116 117 118 119  | Next Page >

  • Online audio stream using ruby on rails

    - by Avdept
    I'm trying to write small website that can stream audio online(radio station) and got few questions: 1. Do i have to index all my music files into database, or i can randomily pick file from file system and play it. 2. When should i use ajax to load new song(right after last finished, or few seconds before to get responce from server with link to file?) 3. Is it worth to use ajax, or better make list, that will play its full time and then start over?

    Read the article

  • Ruby on Rails: custom instance creation failing at redirect

    - by Jack
    I am at an absolute loss as to what I am doing wrong with the following code. I am trying to implement a messaging system within my application, but want it to be handle different types of messages. In this case, I want to create a "request" message of ':message_type = 1'. Instead of using forms as I usually have, I want to make this instance the moment the link is clicked. Here is how I have it set up in the show erb file for "user": <%=link_to "Send friend request", :action=>"request", :controller => "messages", :id => @user.id %> and in the controller: def request @message = Message.new(:sender_id => current_user.id,:user_id => params[:id],:message_type => 1) if @message.save flash[:notice] = 'Message was successfully created.' redirect_to message_path(@message) else redirect_to message_path(@message) end end This results in the following error message: undefined method `rewrite' for nil:NilClass with the trace looking like c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/whiny_nil.rb:52:in `method_missing' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:634:in `url_for' (eval):16:in `message_path' app/controllers/messages_controller.rb:11:in `request' I have used map.resources :messages in the routes.rb file, and done the appropriate :has_many and :belongs_to associations in the models of user and message.

    Read the article

  • Ruby on Rails has_many minimun

    - by user273119
    Look: class User < ActiveRecord::Base has_many :scores, :order => 'score DESC',:autosave =>true, end class Score < ActiveRecord::Base belongs_to :user end Now, I want to order the users by the maximun score of each one, The thing is that i need to get a user, two up and two down users like a top 5 scores how can I do that???? please is urgent!!

    Read the article

  • Network ActiveRecord relation with Rails

    - by Zag zag..
    Hi, I have a has and belongs to many relation between User and Article models, and I would like to link them even if an article if not hosted on the same database then a user. For example, If an article exists at foo.com/articles/3 and a user exists at bar.com/users/1, If would like to be able to do from foo.com web interface or bar.com web interface this kind of query: a_user.articles (or an_article.users). I think this can be possible adding a field like "url" in users and articles tables. But I don't know how to process for ActiveRecord. My Article model looks like this: class Article < ActiveRecord::Base has_and_belongs_to_many :users end Is there yet some example of project using this kind of relation over internet? Many thanks

    Read the article

  • rails db migration, undefined method `to_sym', cant figure out syntax

    - by oelbrenner
    the original migration looks like this: class CreateUsers true do |t| t.string :login, :limit = 40 t.string :name, :limit = 100, :default = '', :null = true t.string :email, :limit = 100 t.string :crypted_password, :limit = 40 t.string :salt, :limit = 40 t.string :remember_token, :limit = 40 t.datetime :remember_token_expires_at t.string :activation_code, :limit = 40 t.datetime :activated_at, :datetime t.string :state, :null = :no, :default = 'passive' t.datetime :deleted_at t.integer :occupation_id, :null = :yes t.datetime :paid_up_to_date, :date t.timestamps end and I am trying to change the default of "state" to be "active" instead of passive so my attempt at a migration looks like this: ( still learning.. be gentle ) class ChangeUserStateDefault < ActiveRecord::Migration def self.up change_column :users, :state, :null = :no, :default = 'active' end def self.down end end

    Read the article

  • content_tag_for a collection in Rails?

    - by Nick
    I have a Post model. Posts have many Comments. I want to generate a <ul> element for post.comments using content_tag_for. Ideally, it'd produce <ul id="comments_post_7" class="comments"> ... </ul> where 7 is the ID of the Post. The closest I can get uses <% content-tag-for :ul post, :comments do %> which produces <ul id="comments_post_7" class="post"> ... </ul> which is pretty close, except for the class="post". Using :class => :comments in the content_tag_for yields class="post comments", but I just want class="comments". It seems logical that I'd be able to use something like <% content_tag_for :ul post.comments do %> but, sadly, that yields <ul id="array_2181653100" class="array"> ... </ul> I've searched far and wide. I feel like I'm missing some elegant way to do this. Am I? Because, seriously, <ul id="comments_post_<%= post.id %>" class="comments"> is painful.

    Read the article

  • JSON is not nested in rails view

    - by SeanGeneva
    I have a several models in a heirarchy, 1:many at each level. Each class is associated only with the class above it and the one below it, ie: L1 course, L2 unit, L3 unit layout, L4 layout fields, L5 table fields (not in code, but a sibling of layout fields) I am trying to build a JSON response of the entire hierarchy. def show @course = Course.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json do @course = Course.find(params[:id]) @units = @course.units.all @unit_layouts = UnitLayout.where(:unit_id => @units) @layout_fields = LayoutField.where(:unit_layout_id => @unit_layouts) response = {:course => @course, :units => @units, :unit_layouts => @unit_layouts, :layout_fields => @layout_fields} respond_to do |format| format.json {render :json => response } end end end end The code is bring back the correct values, but the units, unit_layouts and layout_fields are all nested at the same level under course. I would like them to be nested inside their parent.

    Read the article

  • Rails object inheritence with belongs_to

    - by Rabbott
    I have a simple has_many/belongs_to relationship between Report and Chart. The issue I'm having is that my Chart model is a parent that has children. So in my Report model I have class Report < ActiveRecord::Base has_many :charts end And my Chart model is a parent, where Pie, Line, Bar all inherit from Chart. I'm not sure where the belongs_to :report belongs within the chart model, or children of chart model. I get errors when I attempt to access chart.report because the object is of type "Class" undefined local variable or method `report' for #< Class:0x104974b90 The Chart model uses STI so its pulling say.. 'Pie' from the chart_type column in the charts table.. what am I missing?

    Read the article

  • Rails fixtures seem to be adding extra unexpected data

    - by Mason Jones
    Hello, all. I've got a dynamic fixture CSV file that's generating predictable data for a table in order for my unit tests to do their thing. It's working as expected and filling the table with the data, but when I check the table after the tests run, I'm seeing a number of additional rows of "blank" data (all zeros, etc). Those aren't being created by the fixture, and the unit tests are read-only, just doing selects, so I can't blame the code. There doesn't seem to be any logging done during the fixtures setup, so I can't see when the "blank" data is being inserted. Anyone ever run across this before, or have any ideas of how to log or otherwise see what the fixture setup is doing in order to trace down the source of the blank data?

    Read the article

  • Respond_to in rails

    - by piemesons
    respond_to do |format| format.html format.xml { render :xml => @mah_blogz } end respond_to do |format| format.js end Whats this respond_to, format.html, format.xml and format.js. Whats the purpose, How they work.

    Read the article

  • Rails HTML editor to create forms

    - by Ignace
    Hey all, I'm looking for a HTML editor which can be (easiliy) integrated in a RoR app that has the possibility to create forms. Not forms per se, but I need the possibility to add radiobuttons, input fields, checkboxes and so on. I loved the smoothness of TinyMCE, but apparently this doesn't take me far enough. Does there exists such a gem/plugin? Thanks!

    Read the article

  • Getting the value from an array in the model in rails

    - by slythic
    Hi all, I have a relatively simple problem. I have a model named Item which I've added a status field. The status field will only have two options (Lost or Found). So I created the following array in my Item model: STATUS = [ [1, "Lost"], [2, "Found"]] In my form view I added the following code which works great: <%= collection_select :item, :status, Item::STATUS, :first, :last, {:include_blank => 'Select status'} %> This stores the numeric id (1 or 2) of the status in the database. However, in my show view I can't figure out how to convert from the numeric id (again, 1 or 2) to the text equivalent of Lost or Found. Any ideas on how to get this to work? Is there a better way to go about this? Many thanks, Tony

    Read the article

  • Searching in Rails 3

    - by cbarton
    Here is the situation: I have the need to search for specifics or generals, much like expedia.com or your local library catalog search. In that there are fields that may or may not be filled out based on the individual need. It acts much like an "advanced search page". I have all of that code done for the models/controller and such and have it setup with a Searches controller along with matching model and views. The question that I have is there a way to cut down the amount of parameters posted to GET so that the url isn't search?search[:a]=""+search[:b]=""+search[:c]="x"... plus the unicode checkmark. I only want the filled out fields to be shown in the response link especially minus the checkmark. cbarton

    Read the article

  • Rails -- Cant set value for date_select in form

    - by ChrisWesAllen
    I'm pulling data from an API where the date data comes in as "2008-02-11 00:00:00 " I would like that data to go into my form within the date_select as a value so I can view it correctly before I add it into my database. The view looks like <%= f.label :start_date %><br /> <%= f.date_select :start_date, :value => " #{@stdate[idx]} " %> The object is actually an array of dates since I'm doing this action several times do thats why the [idx] is there; serving as an index. <%= @stdate[idx] % ends up outputting "2008-02-11 00:00:00 " but the fields for the date_select helper only outputs the current date "2010" "June" "5" in those dropdown date selects fields... Do I need to set the values of the Year, Month, and Date Individually? I have Chronic and tried to parse the object before using it as a value for the date_select and that didnt work either. Any ideas?

    Read the article

  • Human readable URL causes a problem in Ruby on Rails

    - by TK
    I have a basic CRUD with "Company" model. To make the company name show up, I did def to_param name.parameterize end Then I accessed http://localhost:3000/companies/american-express which runs show action in the companies controller. Obviously this doesn't work because the show method is as following: def show @company = Company.find_by_id(params[:id]) end The params[:id] is american-express. This string is not stored anywhere. Do I need to store the short string (i.e., "american-express") in the database when I save the record? Or is there any way to retrieve the company data without saving the string in the database?

    Read the article

  • Rails always include (join) on initialize

    - by Seth
    Hello, I have a User model as illustrated below: class User < ActiveRecord belongs_to :college belongs_to :class_level end I want to ALWAYS join with those other two tables returning one simplified User object. How do I accomplish this in my User model. I'm aware that I can do this in another model: class Foo < ActiveRecord has_many :users, :include => [:college, :class_level] end But I want to do this in my User model, so Foo.users will either be eager loaded OR be joined already. Is there a way to create an initialize this in the User model?

    Read the article

  • Sanitizing User Input with Ruby on Rails

    - by phreakre
    I'm writing a very simple CRUD app that takes user stories and stores them into a database so another fellow coder can organize them for a project we're both working on. However, I have come across a problem with sanitizing user input before it is saved into the database. I cannot call the sanitize() function from within the Story model to strip out all of the html/scripting. It requires me to do the following: def sanitize_inputs self.name = ActionController::Base.helpers.sanitize(self.name) unless self.name.nil? self.story = ActionController::Base.helpers.sanitize(self.story) unless self.story.nil? end I want to validate that the user input has been sanitized and I am unsure of two things: 1) When should the user input validation take place? Before the data is saved is pretty obvious, I think, however, should I be processing this stuff in the Controller, before validation, or some other non-obvious area before I validate that the user input has no scripting/html tags? 2) Writing a unit test for this model, how would I verify that the scripting/html is removed besides comparing "This is a malicious code example" to the sanitize(example) output? Thanks in advance.

    Read the article

  • User-customizable rails authorization

    - by neutrino
    Hello everyone, Seems there is an abundance of popular declarative-style authorization plugins, which allow you to somehow state in the code that, e.g., this controller action can be accessed by users with such-and-such roles. But what if I need a more dynamic scheme. I want to have an admin area, with a list of all authorizable actions and an ability to assign permissions on actions from the UI. I have ideas how to implement it from scratch, like to define a model corresponding to a controller and/or action and store the permissions via normal associations. Just wonder if there are any ready solutions to this. Thanks a lot

    Read the article

  • Get SEO friendly URLS with Rails without method_missing?

    - by tesmar
    Hi all, Currently we are using method_missing to catch for calls to SEO friendly actions in our controllers rather than creating actions for every conceivable value for a variable. What we want are URLS like this: /students/BobSmith and NOT /students/show/342 IS there a cleaner solution than method_missing? Thank you!

    Read the article

  • rails - caches_action expire_action

    - by mark
    Hi I want to expire a cached action and wondered how to generate the correct reference. #controller caches_action :index, :layout => false #generates this fragment which works fine views/0.0.0.0:3000/article/someid/posts #sweeper ... expire_action article_posts_path(:article_id => post.article) # results in this Expired fragment: views//en/article/someid/posts (0.0ms) So this is almost ok, except the host is missing. What do I do that supplies this to the expire_action method? Thanks in advance.

    Read the article

  • How to get id of the saved record in Ruby on Rails

    - by railsnew
    I am doing this from the console but I'd like to do this in my code too. Basically I am trying to add a record to the table and then get the id back. >> @record = Physician.create(:pname => "someone2") => #<Physician id: nil, pname: "someone2", pgroup: nil, created_at: nil, updated_at: nil, userid: nil, storeid: nil, licexpdate: nil, address: nil> >> @record.save => false >>

    Read the article

  • Routing error when trying to use same view for update and create flows (Rails 3)

    - by Jamis Charles
    My overall use case: I have a Listing model that has many images. The Listing detail page lists all the fields that can be updated inline (through ajax). I want to be able to use the same view for both update listing and create new listing. My listing controller looks as follows: def detail @listing = Listing.find(params[:id]) @image = Image.new #should this link somewhere else? respond_to do |format| format.html # show.html.erb format.xml { render :xml => @listing } end end def create # create a new listing and save it immediately. Assign it to guest, with a status of "draft" @listing = Listing.new(:price_id => 1) # Default price id # save it to db # TODO add validation that it has to have a price ID, on record creation. So the view doesn't break. @listing.save @image = Image.new # redirect_to "/listings/detail/@listing.id" #this didn't work respond_to do |format| format.html # show.html.erb format.xml { render :xml => @listing } end end The PROBLEM I'm using a partial that shows the same form for the create view and the detail view. This works perfectly except for one thing: When I pull up http://0.0.0.0:3000/listings/detail/7, it works perfectly. When I pull up http://0.0.0.0:3000/listings/new, I get the following error: Showing /Applications/MAMP/htdocs/rails_testing/feedbackd/app/views/listings/_edit_form.html.erb where line #100 raised: No route matches {:action="show", :controller="images"} Extracted source (around line #100): 97: <!-- Form for new images --> 98: <div class="span-20 append-bottom"> 99: <!-- <%# form_for :image, @image, :url => image_path, :html => { :multipart => true } do |f| %> --> 100: <%= form_for @image, :url => image_path, :html => { :multipart => true } do |f| %> 101: <%= f.text_field :description %><br /> 102: <%= f.file_field :photo %> 103: <%= submit_tag "Upload" %> What I think the issue is: When I upload a new image (I'm using Paperclip), it requires the listing_id to create the image record. Since the listing_id isn't passed in with listings/new it can't find the listing_id. How can I pass in the id? Via a redirect? What's the best way to solve this? Thank you.

    Read the article

< Previous Page | 108 109 110 111 112 113 114 115 116 117 118 119  | Next Page >