Search Results

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

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

  • Ruby on Rails: instance & class variables not maintaining value in controller

    - by DerNalia
    at the top of my controller, outside of any method, I have @@javascript_is_disabled = false and I have methods that that the view calls and invokes something like this @@javascript_is_disabled = params[:javascript_disabled] but when I need the @@javascript_is_disabled in completely different method.. it is always false. I know it changes in the method with params args... cause those methods behave differently, and appropriately And ideas?

    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

  • Rails: creating a model in the new action

    - by Joseph Silvashy
    I have an interesting situation, well it's probably not that unique at all, but I'm not totally sure how to tackle it. I have a model, in this case a recipe and the user navigates to the new path /recipes/new however the situation is that I need to be able to have the user upload images and make associations to that model in the new action, but the model doesn't have an ID yet. So I assume I need to rethink my controller, but I don't want to have redirects and whatnot, how can accomplish this? Here is the basic controller, barebones obviously: ... def new # I should be creating the model first, so it has an ID @recipe = Recipe.new end def create @recipe = Recipe.new(params[:recipe]) if @recipe.save redirect_to @recipe else render 'new' end end ... update Perhaps I can have a column thats like state which could have values like new/incomplete/complete or what-have-you. I'm mostly trying to figure out what would also be most efficient for the DB. It would be nice if I could still have a url that said '/new', instead of it be the edit path with the id, for usability sake, but I'm not sure this can be simply accomplished in the new action of my controller. Thoughts?

    Read the article

  • Obfuscating ids in Rails app

    - by fphilipe
    I'm trying to obfuscate all the ids that leave the server, i.e., ids appearing in URLs and in the HTML output. I've written a simple Base62 lib that has the methods encode and decode. Defining—or better—overwriting the id method of an ActiveRecord to return the encoded version of the id and adjusting the controller to load the resource with the decoded params[:id] gives me the desired result. The ids now are base62 encoded in the urls and the response displays the correct resource. Now I started to notice that subresources defined through has_many relationships aren't loading. e.g. I have a record called User that has_many Posts. Now User.find(1).posts is empty although there are posts with user_id = 1. My explanation is that ActiveRecord must be comparing the user_id of Post with the method id of User—which I've overwritten—instead of comparing with self[:id]. So basically this renders my approach useless. What I would like to have is something like defining obfuscates_id in the model and that the rest would be taken care of, i.e., doing all the encoding/decoding at the appropriate locations and preventing ids to be returned by the server. Is there any gem available or does somebody have a hint how to accomplish this? I bet I'm not the first trying this.

    Read the article

  • I am having trouble with my first project in ruby on rails

    - by Sebastian
    Here's my index action in the books controller: http://pastebin.com/XdtGRQKV Here's the view for the action i just mentioned: http://pastebin.com/nQFy400m Here's the result without being logged in: http://i.imgur.com/rQoiw.jpg Here's the result when i'm logged in with the user 'admin': http://i.imgur.com/E1CUr.jpg So the problem is that, in the view, before line 25 the 'user' variable seems to be empty ( or not loaded), and after line 25 the variable 'user' has the expected values. I have tried initializing a variable in the index method of the books controller but get exactly the same results. Thanks in advance! BTW had to make the links text because of stackoverflow limit.

    Read the article

  • Custom Rails Validation (Doesn't seem to be working)

    - by Karl Entwistle
    Hey guys ive got the following Model for Accounts require 'net/http' require 'uri' require 'date' class Account < ActiveRecord::Base validates_presence_of :username, :password, :on => :update validate :valid_expiry_date, :on => :update def valid_expiry_date reply = Net::HTTP.get URI.parse("http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=getaccountdetails_v1&type=prem&login=" + username + "&password=" + password) account = Time.at(reply[80..90].to_i) if (Time.now + 2419200) <= account return true else return false errors.add_to_base("Sorry this account isnt valid") end end end I know the code works in a ruby.rb file and will return true or false, however I seem to be having rather a lot of difficultly trying to translate this code into an actual validation, any help would be much appreciated. Thanks :) Its also defiantly at least connecting to the website as my firewall asked me if the Terminal was aloud to access it. At the moment not only is it displaying no errors its actually letting anything through and saving it.

    Read the article

  • .save puts NULL in user_id field in Ruby on Rails

    - by mathee
    Here's the model file: class ProfileTag < ActiveRecord::Base def self.create_or_update(options = {}) id = options.delete(:id) record = find_by_id(id) || new record.id = id record.attributes = options puts "record.profile_id is" puts record.profile_id record.save! record end end This gives me the correct print out in my log. But it also says that there's a call to UPDATE that sets profile_id to NULL. I'm not sure I understand why the INSERT puts the value into profile_id properly, but then it sets it to NULL on an UPDATE. If you need more specifics, please let me know. I'm thinking that the save functionality does many things other than INSERTs into the database, but I don't know what I need to specify so that it will properly set profile_id.

    Read the article

  • How To Create A Link For "save Image As" To Download an Image In Rails

    - by Kuya
    I want to make a link download like this http://idwallpaper.com/download.php?image_id=1517 I have tried on other tutorial like this <script> function SaveFile(fname){ img.document.execCommand('saveas', null ,fname) } </script> <iframe id="img" src="myimage.jpg" width="(image width + 20)px" height="(image height + 25)px" scrolling="no" frameborder="0px"></iframe> <button onclick="SaveFile('myimage.jpg');">save as</button> Does not work in FireFox though.....

    Read the article

  • Ruby on Rails POST parameters on redirect_to

    - by Splashlin
    I have to make a call to a different url in one of my controllers on my site. The problem is that with all the parameters the other site requires I'm overflowing the url. Is there anyway to call another url from the controller and send all of the parameters using a POST? I'm not expecting a response from the other site. Also, I think there's a way to do this using the Net::HTTP library thought I'm not sure how. Thanks

    Read the article

  • Using before_create in Rails to normalize a many to many table

    - by weotch
    I am working on a pretty standard tagging implementation for a table of recipes. There is a many to many relationship between recipes and tags so the tags table will be normalized. Here are my models: class Recipe < ActiveRecord::Base has_many :tag_joins, :as => :parent has_many :tags, :through => :tag_joins end class TagJoin < ActiveRecord::Base belongs_to :parent, :polymorphic => true belongs_to :tag, :counter_cache => :usage_count end class Tag < ActiveRecord::Base has_many :tag_joins, :as => :parent has_many :recipes, :through => :tag_joins, :source => :parent , :source_type => 'Recipe' before_create :normalizeTable def normalizeTable t = Tag.find_by_name(self.name) if (t) j = TagJoin.new j.parent_type = self.tag_joins.parent_type j.parent_id = self.tag_joins.parent_id j.tag_id = t.id return false end end end The last bit, the before_create callback, is what I'm trying to get working. My goal is if there is an attempt to create a new tag with the same name as one already in the table, only a single row in the join table is produced, using the existing row in tags. Currently the code dies with: undefined method `parent_type' for #<Class:0x102f5ce38> Any suggestions?

    Read the article

  • Operations inside Rails I18n locales' strings

    - by Cristobal Viedma
    Hi, I am trying to put operations inside the locales to adapt to different languages. For example, in English a billion is 1,000,000,000, however in Spanish a billion is 1,000,000,000,000 so I would like to be able to have the following: en: billion: "You have %{money} billions" es: billion: "Tienes %{money/1000.0} billones" In order to be able to write: I18n.t :billion, :money => whatever And be right for whatever language. However, it seems that I cannot put operations inside the locales' strings. Any hint on how should I be doing this? Maybe my approach is just wrong "philosophically" talking? Thanks all!

    Read the article

  • Rails has_one vs belongs_to semantics

    - by Anurag
    I have a model representing a Content item that contains some images. The number of images are fixed as these image references are very specific to the content. For example, the Content model refers to the Image model twice (profile image, and background image). I am trying to avoid a generic has_many, and sticking to multiple has_one's. The current database structure looks like: contents - id:integer - integer:profile_image_id - integer:background_image_id images - integer:id - string:filename - integer:content_id I just can't figure out how to setup the associations correctly here. The Content model could contain two belongs_to references to an Image, but that doesn't seem semantically right cause ideally an image belongs to the content, or in other words, the content has two images. This is the best I could think of (by breaking the semantics): class Content belongs_to :profile_image, :class_name => 'Image', :foreign_key => 'profile_image_id' belongs_to :background_image, :class_name => 'Image', :foreign_key => 'background_image_id' end Am I way off, and there a better way to achieve this association?

    Read the article

  • Rails 3) Delete, Destory, and Routing

    - by Maximus S
    The problem is the code below <%= button_to t('.delete'), @post, :method => :delete, :class => :destroy %> My Post model has many relations that are dependent on delete. However, the code above will only remove the post, leaving its relations intact. The problem is that methods delete and destroy are different in that method delete doesn't instantiate the object. So I need to use "destroy" instead of "delete" my post. <%= button_to t('.delete'), @post, :method => :destroy %> gives me routing error. No route matches [POST] "/posts/2" <%= button_to t('.delete'), @post, Post.destroy(@post) %> deletes the post without clicking the button. Could anyone help me with this? UPDATE: application.js //= require jquery //= require jquery-ui //= require jquery_ujs //= require bootstrap-modal //= require bootstrap-typeahead //= require_tree . rake routes DELETE (/:locale)/posts/:id(.:format) posts#destroy Post model has_many :tag_links, :dependent => :destroy has_many :tags, :through => :tag_links Tag model has_many :tag_links, :dependent => :destroy has_many :posts, :through => :tag_links Problem: When I delete a post, all the tag_links are destroyed but tags still exist.

    Read the article

  • Namespace with index action in Rails

    - by yuval
    I have an admin controller located inside /controllers/admin/admin_controller.rb I also have a pages controller located inside /controllers/admin/pages_controller.rb In my routes.rb file, I have the following: map.namespace :admin do |admin| admin.resources :pages end When the user goes to localhost:3000/admin, I'd like the user to see a page with a link to /admin/pages (Pages CRUD) and to / (To go back home). Since I am using a namespace, I cannot have an index action for /admin. How would I get this done and still have my controllers located inside my /controllers/admin folder (rather than using admin as a map.resources component and a has_many association to pages). Please note I am only interested in the show action of admin. Thank you!

    Read the article

  • Get methods params type parsing wsdl file in a rails/ruby application

    - by Marco Sangiorgi
    Hi, I have a question about ruby and wsdl soap. I couldn't find a way to get each method's params and their type. For example, if I found out that a soap has a methods called "get_user_information" (using wsdlDriver) is there a way to know if this method requires some params and what type of params does it require (int, string, complex type, ecc..)? I'd like to be able to build html forms from a remote wsdl for each method... Sorry for my horrible English :D

    Read the article

  • How to test Gem Extensions in Rails

    - by rube_noob
    I have written an extension to an existing gem (that is stored in lib) and a corresponding test for my extension. How could I go about running the gem's tests as well as my own automatically. What is the best practice for this case?

    Read the article

  • Ruby on Rails - observe_field help

    - by miligraf
    Trying to put in field "pagar" the calculated value of "precio" * 15% but I don't know why it is not working :S <% form_for @libro, :html => { :multipart => true } do |f| %> <%= f.label "Precio (si es venta):" %> <%= f.text_field :precio %> <%= observe_field :libro_precio, :frequency => 0.25, :update => :libro_pagar, :with => 'value*0.15' %> <%= f.label "A pagar (si es venta):" %> <%= f.text_field :pagar %> <% end %>

    Read the article

  • My partial is not where rails expects it to be (nested partials)

    - by new2ruby
    I have a model Submissions which has many Performers. I have a partial for showing an individual submissions (app/views/submissions/_submission.html.erb): <div> Show stuff relating to @submission ... <%= render @performers %> </div> and a partial for showing performers (app/views/performers/_performer.html.erb): <%= div_for performer do %> <%= performer.name %> <% end %> This works fine from (app/views/submissions/show.html.erb): <%= render @submission %> But I want to use this from a different namespace too (app/views/curator/submissions/show.html.erb). But I get this error: Missing partial curator/submissions/submission with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/Users/ircmullaney/RubyCode/cif/app/views" * "/Users/ircmullaney/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/devise-2.1.2/app/views" I can fix this by changing the render to this: <%= render 'submissions/submission' %> But, then the nested partial fails: Missing partial curator/performers/performer with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/Users/ircmullaney/RubyCode/cif/app/views" * "/Users/ircmullaney/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/devise-2.1.2/app/views" This doesn't work: <%= render 'performers/performer' %> because of the div_for: undefined method `model_name' for NilClass:Class Any ideas how I should do this?

    Read the article

  • Background processing in Rails

    - by Shreyas Satish
    A certain function in my controller takes a lot of time to process (heavy db work) . So when my user clicks on "submit" on the form he has to wait for the process to complete which is quite long. Is there any way that on "submitting", the user is redirected to the next view without any delay while the processing continues in the back-end without making the user wait ? Thanks & Cheers !

    Read the article

  • Where to put code snippets in Rails?

    - by Nik
    Hello all, I have this code snippets that generates a signature for POSTs. The detail of it is not important, but what I want to know is: since it is not a model-related chunk of code, it really can be use anywhere: in controllers, in models, in view helpers; even in views. So I am unsure where and, even bigger of a problem, how to activate the use of it once I place it in some location. Is it what those "require" statements are all about? That you can acquire some functionality through a "require" statement in the current file you are working on? Just so that we have an example to talk about, say, I have a little snippet of code that does cubing: def cube_it(num) num**3 end I know that I will be using it in various places across the application, so where should I put it? and when I do need to use it, how can I "summon" it? Thank You

    Read the article

  • Rails: RESTful Find, Initialize, or Create

    - by Andrew
    I have an app that has Cities in it. I'm looking for some suggestions on how to RESTfully structure a controller so that I can lookup, initialize, and create city records via AJAX requests. For instance: Given a text field city_name A user enters the name of a City, like "Paris, France" The app checks this location to see if there is such a city in the database already If there is, it returns the city object If there is not, it returns a new record initialized with the name "Paris" and the country "France", and prompts the user to confirm they want to add this city to the database If the user says "Yes" the record is saved. If not the record is discarded and the form is cleared. Now, my first approach was to change the Create action to use find_or_create, so that an AJAX post to cities_path would result in either returning the existing city or creating it and returning it. That works ok... However, it would be better to setup controller actions that would take a string input, find , or else initialize and return, then only create if the user confirms the generated record is correct. The ideal scenario would put this all in one action so AJAX request can go to that url, the server responds with JSON objects, and javascript can handle things from there. I'd like to keep all the user-interaction logic client side, and also minimize the number of requests it takes to achieve this. Any suggestions on the cleanest, most RESTful way to accomplish this?

    Read the article

  • Ignore first line on csv parse Rails

    - by Jack
    Hi, I am using the code from this tutorial to parse a CSV file and add the contents to a database table. How would I ignore the first line of the CSV file? The controller code is below: def csv_import @parsed_file=CSV::Reader.parse(params[:dump][:file]) n = 0 @parsed_file.each do |row| s = Student.new s.name = row[0] s.cid = row[1] s.year_id = find_year_id_from_year_title(row[2]) if s.save n = n+1 GC.start if n%50==0 end flash.now[:message] = "CSV Import Successful, #{n} new students added to the database." end redirect_to(students_url) end

    Read the article

  • Deep relationships in Rails

    - by Neil Middleton
    I have some projects. Those projects have users through memberships. However, those users belong to companies. Question is, how do I find out which companies can access a project? Ideally I'd be able to do project.users.companies, but that won't work. Is there a nice, pleasant way of doing this?

    Read the article

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